home *** CD-ROM | disk | FTP | other *** search
/ LSD Docs / LSD Docs.iso / FILEZ / lsd34.dms / lsd34.adf / AREXX.doc2.pp / AREXX.doc2
Text File  |  1990-09-13  |  156KB  |  3,499 lines

  1.             AREXX USER'S REFERENCE MANUAL
  2.  
  3.                                  PART 2
  4.  
  5.             CHAPTER 7 TRACING AND INTERRUPTS
  6.  
  7. ARexx provides tracing and source-level debugging facilities that are unusual
  8. in a high-level language. Tracing refers to the ability to display selected
  9. statements in a program as the program executes. When a clause is traced,its
  10. line number,source text,and related information are displayed on the console.
  11. The tracing action of the interpreter is determined by a trace option that
  12. selects which source clauses will be traced,and two modifier flags that control
  13. command inhibition and interactive tracing.
  14.  
  15. The internal interrupt system enables an ARexx program to detect certain
  16. synchronous or asynchronous events and to take special actions when they occur.
  17. Events such as a syntax error or an external halt request that would normally
  18. cause the program to exit can instead be trapped so that corrective actions can
  19. be taken.
  20.  
  21. 7-1 TRACING OPTIONS
  22.  
  23. Trace options are sometimes called an alphabetic options,since the keywords
  24. that select an option can be shortened to one letter for convenience. The
  25. alphabetic options are:
  26.  
  27. ALL. All clauses are traced.
  28. COMMANDS. All command clauses are traced before being sent to the external
  29. host. Non-zero return codes are displayed on the console.
  30. ERRORS. Commands that generate a non-zero return code are traced after the
  31. clause is executed.
  32. INTERMEDIATES. All clauses are traced,and intermediate results are displayed
  33. during expression evaluation. These include the values retrieved for variables,
  34. expanded compound names,and the results of function calls.
  35. LABELS. All label clauses are traced as they are executed. A label will be
  36. displayed each time a transfer of control takes place.
  37. NORMAL. Command clauses will return codes that exceed the current error failure
  38. level are traced after execution,and an error message is displayed. This is the
  39. default trace option.
  40. RESULTS. All clauses are traced before execution,and the final result of each
  41. expression is displayed. Values assigned to variables by ARG,PARSE,or PULL
  42. instructions are also displayed.
  43. SCAN. This is a special option that traces all clauses and checks for errors,
  44. but suppresses the actual execution of the statements. It is helpful as a
  45. preliminary screening steop for a newly-created program.
  46.  
  47. The tracing mode can be set using either the TRACE instruction or the TRACE()
  48. Built-In function. The RESULTS trace option is recommended for general-purpose
  49. testing. Tracing can be selectively disabled from within a program so that
  50. previously-tested parts of a program can be skipped.
  51.  
  52.                 71
  53.  
  54. 7-2 DISPLAY FORMATTING
  55.  
  56. Each trace line displayed on the console is indented to show the effective
  57. control(nesting)level at that clause,and is identified by a special three-
  58. character code,as shown in Table 7.1 below. The source for each clause is
  59. preceded by its line number in the program. Expression results or intermediates
  60. are enclosed in double quotes so that leading and trailing blanks will be
  61. apparent.
  62.  
  63.             TABLE 7.1 TRACING PREFIX CODES
  64.         
  65.         CODE        DISPLAYED VALUES
  66.         +++        Command or syntax error
  67.         >C>        Expanded compound name
  68.         >F>        Result of a function call
  69.         >L>        Label clause
  70.         >O>        Result of a dyadic operation
  71.         >P>        Result of a prefix operation
  72.         >U>        Uninitialized variable
  73.         >V>        Value of a variable
  74.         >>>        Expression or template result
  75.         >.>        "Placeholder" token value
  76.  
  77. TRACING OUTPUT
  78.  
  79. The tracing output from a program is always directed to one of two logical
  80. streams. The interpreter first checks for a stream named STDERR,and directs the
  81. output there if the steam exists. Otherwise the trace output goes to the
  82. standard output stream STDOUT and will be interleaved with the normal console
  83. output of the program. The STDERR and STDOUT streams can be opened and closed
  84. under program control,so the programmer has complete control over the
  85. destination of tracing output.
  86.  
  87. In some cases a program may not have a predefined output stream. For example,a
  88. program invoked from a host application that did not provide input and output
  89. streams would not have an output console. To provide a tracing facility for
  90. such programs,the resident process can open a special global tracing console
  91. for use by any active program. When this console opens,the interpreter
  92. automatically opens a stream named STDERR for each ARexx program in which
  93. STDERR is not currently defined,and the program then diverts its tracing output
  94. to the new stream.
  95.  
  96. The global console can be opened and closed using the command utilities too and
  97. tcc,respectively. The console may not close immediately upon request,however.
  98. The resident process waits until all active programs have diverted their
  99. tracing streams back to the default state before actually closing the console.
  100. Applications programs may provide direct control over the tracing console by
  101. sending request packets to the resident process,which is discussed in Chapter
  102. 10.
  103.  
  104. The trace stream(STDERR or STDOUT)is also used for trace input,so a program in
  105. interactive tracing mode will wait for user input from this console. The global
  106. tracing console is always shared among all currently active programs. Since it
  107. may be confusing to have several programs simultaneously writing to the same
  108. console,it is recommended that only one program at a time be traced using the
  109. global console.
  110.  
  111.                 72
  112.  
  113. COMMAND INHIBITION
  114.  
  115. ARexx provides a tracing mode called command inhibition that suppresses host
  116. commands. In this mode command clauses are evaluated in the normal manner,but
  117. the command is not actually sent to the external host,and the return code is
  118. set to zero. This provides a way to test programs that issue potentially
  119. destructive commands,such as erasing files or formatting disks. Command
  120. inhibition does not apply to command clauses that are entered interactively.
  121. These commands are always performed,but the value of the special variable RC is
  122. left unchanged.
  123.  
  124. Command inhibition may be used in conjunction with any trace option. It is
  125. controlled by the "!" character,which may appear by itself or may precede any
  126. of the alphabetic options in a TRACE instruction. Each occurrence of the "!"
  127. character "toggles" the inhibition mode currently in effect. Command inhibition
  128. is cleared when tracing is set to OFF.
  129.  
  130. 7-3 INTERACTIVE TRACING
  131.  
  132. Interactive tracing is a debugging facility that allows the user to enter
  133. source statements while a program is executing. These statements may be used to
  134. examine or modify variable values,issue commands,or otherwise interact with the
  135. program. Any valid language statements can be entered interactively,with the
  136. same rules and restrictions that apply to the INTERPRET instruction. In
  137. particular,compound statements such as DO and SELECT must be complete within
  138. the entered line.
  139.  
  140. Interactive tracing can be used with any of the trace options. While in
  141. interactive tracing mode,the interpreter pauses after each traced clause and
  142. prompts for input with the code "+++." At each pause,three types of user
  143. responses are possible.
  144.  
  145.     If a null line is entered,the program continues to the next pause
  146.     point.
  147.     If an "=" character is entered,the preceding clause is executed again.
  148.     Any other input is treated as a debugging statement,and is scanned and
  149.     executed.
  150.  
  151. The pause points during interactive tracing are determined by the tracing
  152. option currently in effect,as the interpreter pauses only after a traced
  153. clause. However,certain instructions cannot be safely(or sensibly)re-executed,
  154. so the interpreter will not pause after executing one of these. The "no-pause"
  155. instructions are CALL,DO,ELSE,IF,THEN,and OTHERWISE. The interpreter will also
  156. not pause after any clause that generate and execution error.
  157.  
  158. Interactive tracing mode is controlled by the "?" character,either by itself or
  159. in combination with an alphabetic trace option. Any number of "?" characters
  160. may precede an option,and each occurrence toggles the mode currently in effect.
  161. For example,if the current trace option was NORMAL,then "TRACE ?R" would set
  162. the option to RESULTS and select interactive tracing mode. A subsequent "TRACE
  163. ?" would turn off interactive tracing.
  164.  
  165.                 73
  166.  
  167. ERROR PROCESSING
  168.  
  169. The ARexx interpreter provides special error processing while it executes
  170. debugging statements. Errors that occur during interactive debugging are
  171. reported,but do not cause the program to terminate. This special processing
  172. applies only to the statements that were entered interactively. Errors occuring
  173. in the program source statements are treated in the usual way whether or not
  174. the interpreter is in interactive tracing mode.
  175.  
  176. In addition to the special error processing,the interpreter also disables the
  177. internal interrupt flags during interactive debugging. This is necessary to
  178. prevent an accidental transfer of control due to an error or uninitialized
  179. variable. However,if a "SIGNAL label" instruction is entered,the transfer will
  180. take place,and any remaining interactive input will be abandoned. The SIGNAL
  181. instruction can still be used to alter the interrupt flags,and the new settings
  182. will take effect when the interpreter returns to normal processing.
  183.  
  184. THE EXTERNAL TRACING FLAG
  185.  
  186. The ARexx resident process maintains an external tracing flag that can be used
  187. to force programs into interactive tracing mode. The tracing flag can be set
  188. using the ts command utility. When the flag is set,any program not already in
  189. interactive tracing mode will enter it immediately. The internal trace option
  190. is set to RESULTS unless it is currently set to INTERMEDIATES or SCAN,in which
  191. case it remains unchanged. Programs invoked while the external tracing flag is
  192. set will begin executing in interactive tracing mode.
  193.  
  194. The external tracing flag provides a way to regain control over programs that
  195. are caught in loops or are otherwise unresponsive. Once a program enters
  196. interactive tracing mode,the user can step through the program statements and
  197. diagnose the problem. There is one caveat,though:external tracing is global
  198. flag,so all currently-active programs are affected by it. The tracing flag
  199. remains set until it is cleared using the "te" command utility. Each program
  200. maintains an internal copy of the last state of the tracing flag,and sets its
  201. tracing option to OFF when it observes that the tracing flag has been cleared.
  202.  
  203. 7-4 INTERRUPTS
  204.  
  205. ARexx maintains an internal interrupt system that can be used to detect and
  206. trap certain error conditions. When an interrupt is enabled and its
  207. corresponding condition arises,a transfer of control to the label specific to
  208. that interrupt occurs. This allows a program to retain control in circumstances
  209. that might otherwise cause the program to terminate. The interrupt conditions
  210. can caused by either synchronous events like a syntax error,or asynchronous
  211. events like a "control-C" break request. Note that these internal interrupts
  212. are completely separate from the hardware interrupt system managed by the EXEC
  213. operating system.
  214.  
  215. The interrupts supported by ARexx are described below. The name assigned to
  216. each is actually the label to which control will be tranferred. Thus,a SYNTAX
  217. interrupt will transfer control to the label "SYNTAX:." Interrupts can be
  218. enabled or disabled using the SIGNAL instruction. For example,the instruction
  219. "SIGNAL ON SYNTAX" would enable the SYNTAX interrupt.
  220.  
  221.                 74
  222.  
  223. BREAK_C. This interrupt will trap a control-C break request generated by DOS.
  224. If the interrupt is not enabled,the program terminates immediately with the
  225. error message "Execution halted" and returns with the error code set to 2.
  226.  
  227. BREAK_D. The interrupt will detect and trap a control-D break request issued by
  228. DOS. The break request is ignored if the interrupt is not enabled.
  229.  
  230. BREAK_E. The interrupt will detect and trap a control-E break request issued by
  231. DOS. The break request is ignored if the interrupt is not enabled.
  232.  
  233. BREAK_F. The interrupt will detect and trap a control-F break request issued by
  234. DOS. The break request is ignored if the interrupt is not enabled.
  235.  
  236. ERROR. This interrupt is generated by any host command that returns a non-zero
  237. code.
  238.  
  239. HALT. An external halt request will be trapped if this interrupt is enabled.
  240. Otherwise,the program terminates immediately with the error message "Execution
  241. halted" and returns with the error code set to 2.
  242.  
  243. IOERR. Errors detected by the I/O system will be trapped if this interrupt is
  244. enabled.
  245.  
  246. NOVALUE. An interrupt will occur if an uninitialized variable is used while
  247. this condition is enabled. The usage could be within an expression,in the UPPER
  248. instruction,or with the VALUE()built-in function.
  249.  
  250. SYNTAX. A syntax or execution error will generate this interrupt. Not all
  251. errors such errors can be trapped,however. In particular,certain errors
  252. occurring before a program is actually executing,and those detected by the
  253. ARexx external interface,cannot be trapped by the SYNTAX interrupt.
  254.  
  255. When an interrupt forces a transfer of control,all of the currently active
  256. control ranges are dismantled,and the interrupt that caused the transfer is
  257. disabled. This latter action is necessary to prevent a possible recursive
  258. interrupt loop. Only the control structures in the current environment are
  259. affected,so an interrupt generated within a function will not affect the
  260. caller's environment.
  261.  
  262. SPECIAL VARIABLES. Two special variables are affected when an interrupt occurs.
  263. The variable SIGL is always set to the current line number before the transfer
  264. of control takes place,so that the program can determine which source line was
  265. being executed. When an ERROR or SYNTAX interrupt occurs,the variable RC is set
  266. to the error code that caused the condition. For ERROR interrupts this value
  267. will be a command return code,and can usually be interpreted as an error
  268. severity level. The value for SYNTAX interrupts is always an ARexx error code.
  269.  
  270. Interrupts are useful primarily to allow a program to take special
  271. error-recovery actions. Such actions might involve informing external programs
  272. that an error ocurred,or simply reporting further diagnostics to help in
  273. isolating the problem. In the following example,the program issues a "message"
  274. command to an external host called "MyEdit" whenever a syntax error is
  275. detected:
  276.  
  277.                 75
  278.  
  279.     /* A macro program for 'MyEdit'            */
  280.     signal on syntax    /* enable interrupt    */
  281.       .
  282.       . (normal processing)
  283.       .
  284.     exit
  285.     syntax:            /* syntax error detected*/
  286.        address 'MyEdit'
  287.        'message' 'error' rc errortext(rc)
  288.        exit 10
  289.  
  290.                 76
  291.  
  292.             CHAPTER 8 PARSING AND TEMPLATES
  293.  
  294. Parsing is a operation that extracts substrings from a string and assigns them
  295. to variables. It corresponds roughly to the notion of a "formatted read" used
  296. in other languages,but has been generalized in the several ways. Parsing is
  297. performed using the PARSE instruction or its variants ARG and PULL. The input
  298. for the operation is called the parse string and can come from several sources;
  299. these source options are described with the PARSE instruction in Chapter 4.
  300.  
  301. Parsing is controlled by a template,a group of tokens that specifies both the
  302. variables to be given values and the way to determine the value strings.
  303. Templates were described briefly with the PARSE instruction;the present chapter
  304. presents a more formal description of their structure and operation.
  305.  
  306. 8-1 TEMPLATE STRUCTURE
  307.  
  308. The tokens that are valid in a template are symbols,strings,operators,
  309. parentheses,and commas. Any blanks that may be present as separators are
  310. removed before the template is processed. The tokens in a template ultimately
  311. serve to specify one of the two basic template objects:
  312.  
  313. Markers determine a scan position within the parse string,and
  314. Targets are symbols to be assigned a value.
  315.  
  316. With these objects in mind,the parsing process can be described as one of
  317. associating with each target a starting and ending position in the parse
  318. string. The substring between these positions then becomes the value for the
  319. target.
  320.  
  321. MARKETS. There are three types of marker objects:
  322.  
  323. ABSOLUTE markers specify an actual index position in the parse string,
  324. RELATIVE markers specify a positive or negative offset from the current
  325. position,and
  326. PATTERN markers specify a position implicitly,by matching the pattern against
  327. the parse string beginning at the current scan position.
  328.  
  329. TARGETS. Targets,like markers,can affect the scan position if value strings are
  330. being extracted by tokenization. Parsing by tokenization extracts words(tokens)
  331. from the parse string, and is used whenever a target is followed immediately
  332.  
  333.                 77
  334.  
  335. by another target. During tokenization the current scan position is advanced
  336. past any blanks to the start of the next word. The ending index is the position
  337. just past the end of the word,so that the value string has neither leading nor
  338. trailing blanks.
  339.  
  340. TEMPLATE OBJECTS
  341.  
  342. Each template object is specified by one or more tokens,which have the
  343. following interpretations.
  344.  
  345. SYMBOLS. A symbol token may specify either a target or a marker object. If it
  346. follows an operator token(+,-,or=),it represents a marker,and the symbol value
  347. is used as an absolute or relative position. Symbols enclosed in parentheses
  348. specify pattern markers,and the symbol value is used as the pattern string.
  349.  
  350. If neither of the preceding cases applies and the symbol is a variable,then it
  351. specifies a target. Fixed symbols always specify absolute markers and must be
  352. whole numbers,except for the period(.)symbol which defines a placeholder
  353. target.
  354.  
  355. STRINGS. A string token always represents a pattern marker.
  356.  
  357. PARENTHESES. A symbol enclosed in parentheses is a pattern marker,and the value
  358. of the symbol is used as the pattern string. While the symbol may be either
  359. fixed or variable,it will usually be a variable,since a fixed pattern could be
  360. given more simply as a string.
  361.  
  362. OPERATORS. The three operators "+,"-,"and "=" are valid within a template,and
  363. must be followed by a fixed or variable symbol. The value of the symbol is used
  364. as a marker and must therefore represent a whole number. The "+" and "-"
  365. operators signify a relative marker,whose value is negated by the "-" operator.
  366. The "=" operator indicates an absolute marker,and is optional if the marker is
  367. defined by a fixed symbol.
  368.  
  369. COMMAS. The comma(,)marks the end of a template,and is used as a separator when
  370. multiple templates are provided with an instruction. The interpreter obtains a
  371. new parse string before processing each succeeding template. For some source
  372. options,the new string will be identical to the previous one. The ARG,EXTERNAL,
  373. and PULL options will generally supply a different string,as will the VAR
  374. option if the variable has been modified.
  375.  
  376. THE SCANNING PROCESS
  377.  
  378. Scan positions are expressed as an index in the parse string,and can range from
  379. 1(the start of the string)to the length of the string plus 1(the end). An
  380. attempt to set the scan position before the start or after the end of the
  381. string instead sets it to the beginning or end,respectively.
  382.  
  383. The substring specified by two scan indices includes the characters from the
  384. starting position up to,but not including,the ending position. For example,the
  385. indices 1 and 10 specify characters 1-9 in the parse string. One additional
  386. rule is applied if the second scan index is less than or equal to the first: in
  387. this case the remainder of the parse string is used as the substring. This
  388. means that a template specificaiton like
  389.                 78
  390.  
  391.     parse arg 1 all 1 first second
  392.  
  393. will assign the entire parse string to the variable ALL. Of course,if the
  394. current scan index is already at the end of the parse string,then the remainder
  395. is just the null string.
  396.  
  397. When a pattern marker is matched against the parse string,the marker position
  398. is the index of the first character of the matched pattern,or the end of the
  399. string if no match was found. The pattern is removed from the string whenever a
  400. match is found. This is the only operation that modifies the parse string
  401. during the parsing process.
  402.  
  403. Templates are scanned from left to right with the initial scan index set to 1,
  404. the start of the parse string. The scan position is updated each time a marker
  405. object is encountered,according to the type and value of the marker. Whenever a
  406. target object is found,the value to be assigned is determined by examining the
  407. next template object. If the next object is another target,the value string is
  408. determined by tokenizing the parse string. Otherwise,the current scan position
  409. is used as the start of the value string,and the position specified by the
  410. following marker is used as the end point.
  411.  
  412. The scan continous until all of the objects in the template have been used.
  413. Note that every target will be assigned a value;once the parse string has been
  414. exhausted,the null string is assigned to any remaining targets.
  415.  
  416. 8-2 TEMPLATES IN ACTION
  417.  
  418. The preceding section is rather abstract,so let's look now at some examples of
  419. parsing with templates.
  420.  
  421. PARSING BY TOKENIZATION
  422.  
  423. Computer programs frequently require splitting a string into its component
  424. words or tokens. This is easily accomplished with a template consisting
  425. entirely of variables(targets).
  426.  
  427.     /* Assume "hammer 1 each $600.00" was entered    */
  428.     pull item qty untils cost .
  429.  
  430. In this example the input line from the PULL instruction is split into words
  431. and assigned to the variables in the template. The variable item receives the
  432. value "hammer," qty is set to "1," units is set to "each," and cost gets the
  433. value "$600.00." The final placeholder(.) is given a null value,since there are
  434. only four words in the input. However,it forces the preceding variable cost to
  435. be given a tokenized value. If the placeholder were omitted,the remainder of
  436. the parse string would be assigned to cost,which would then have a leading
  437. blank.
  438.  
  439. In the next example,the first word of a string is removed and the remainder is
  440. placed back in the string. The process continues until no more words are
  441. extracted.
  442.  
  443.                 79
  444.  
  445.     /* Assume "result" contains a string of words    */
  446.     do forever
  447.        /* Get first word of string            */
  448.        parse var result first result
  449.        if first == '' then leave
  450.        /* ... process words ...            */
  451.        end
  452.  
  453. PATTERN PARSING
  454.  
  455. The next example uses pattern markers to extract the desired fields. The
  456. "pattern" in this case is very simple -- just a single character -- but in
  457. general can be an arbitrary string of any length. This form of parsing is
  458. useful whenever delimiter characters are present in the parse string.
  459.  
  460.     /* Assume an argument string "12,34.5,1        */
  461.     arg hours ',' rate ',' withhold
  462.  
  463. Keep in mind that the pattern is actually removed from the parse string when a
  464. match is found. If the parse string is scanned again from the beginning,the
  465. length and structure of the string may be different than at the start of the
  466. parsing process. However,the original source of the string is never modified.
  467.  
  468. POSITIONAL MARKERS
  469.  
  470. Parsing with positional markers is used whenever the fields of interest are
  471. known to be in certain positions in a string. In the next example,the records
  472. being processed contain a variable length field. The starting position and
  473. length of the field are given in the first part of the record,and a variable
  474. positional marker is used to extact the desired field.
  475.  
  476.     /* records look like:                */
  477.     /* start:   1-5                    */
  478.     /* length:  6-10                */
  479.     /* name:    @(start,length)            */
  480.     parse value record with 1 start +5 length +5 =start name +length
  481.  
  482. The "=start" sequence in the above example is an absolute marker whose value is
  483. the position paced in the variable start earlier in the scan. The "+length"
  484. sequence supplies the effective length of the field.
  485.  
  486. MULTIPLE TEMPLATES
  487.  
  488. It is sometimes useful to specify more than one template with an instruction,
  489. which can be done by separating the templates with a comma. In this next
  490. example,the ARG instruction(or PARSE UPPER ARG)is used to access the argument
  491. strings provided when the program was called. Each template accesses the
  492. succeeding argument string.
  493.  
  494.                 80
  495.  
  496.     /* Assume arguments were ('one two',12,sort)    */
  497.     arg first second,amount,action,option
  498.  
  499. The first template consists of the variables first and second,which are set to
  500. the values "one" and "two,"respectively. In the next two templates amount gets
  501. the value "12" and action is set to "SORT". The last template consists of the
  502. variable "option,"which is set to the null string,since only three arguments
  503. were available.
  504.  
  505. When multiple templates are used with the EXTERNAL or PULL source options,each
  506. additional template requests an additional line of input from the user. In the
  507. next example two lines of input are read:
  508.  
  509.     /* read last,first,and middle names and ssn    */
  510.     pull last ',' first middle,ssn
  511.  
  512. The first input line is expected to have three words,the first of which is
  513. followed by a comma,which are assigned to the variables last,first,and middle.
  514. The entire second input line is assigned to the variable ssn.
  515.  
  516. Multiple templates can be useful even with a source option that returns the
  517. identical parse string. If the first template included pattern markers that
  518. altered the parse string,the subsequent templates could still access the
  519. original string. Note that subsequent parse strings obtained from the VALUE
  520. source do not cause the expression to be reevaluated,but only retrieve the
  521. prior result.
  522.  
  523.                 81
  524.  
  525.             CHAPTER 9 THE RESIDENT PROCESS
  526.  
  527. This chapter describes some of the capabilities of the ARexx resident process,
  528. a global communications and resources manager. The material presented here is
  529. directed to the general user;Chapter 10 covers these topics in greater depth
  530. for software developers who wish to integrate ARexx with other applications
  531. programs.
  532.  
  533. The resident process must be active before any ARexx programs can be run. It
  534. announces its presence to the system by opening a public message port named
  535. "REXX,"so applications programs that use ARexx should check for the presence of
  536. this port. If the port is not open,the user can either be informed that the
  537. macro processor is not available,or else the applications program can start up
  538. the resident process. The latter option can be done using the rexxmast command.
  539.  
  540. The primary function of the resident process is to launch ARexx programs. When
  541. an applications program sends a "command" or "function" message to the "REXX"
  542. port,the resident process creates a new DOS process to execute the program, and
  543. forwards the invocation message to newly created process. It also creates a new
  544. instance of the ARexx global data structure,which links together all of the
  545. structures manipulated by the program.
  546.  
  547. In addition to launching programs,the resident process managers various
  548. resources used by ARexx. These resources include a list of available function
  549. libraries called the Library List,a list of(name,value)pairs called the Clip
  550. List,and a list of the currently active ARexx programs. Built-In functions are
  551. available to manipulate the Library List and Clip List from within an ARexx
  552. program. Applications programs can modify a resource list either by sending a
  553. request packet to the resident process or by direct manipulation of the list.
  554.  
  555. 9-1 COMMAND UTILITIES
  556.  
  557. ARexx is supplied with a number of command utilities to provide various control
  558. functions. These are executable modules that can be run from the CLI,and should
  559. reside in the system command(C:)directory for convenience. These commands are
  560. relevant only when the ARexx resident process is active.
  561.  
  562. The functions performed by these utilities may also be available from within an
  563. applications program. All of the utilities are implemented by sending message
  564. packets to the resident process,so an application designed to work closely with
  565. ARexx could easily provide these functions as part of its control menu.
  566.  
  567. HI
  568. Usage:HI
  569. Sets the global halt flag,which causes all active programs to receive an
  570. external halt request. Each program will exit immediately unless its HALT
  571. interrupt has been enabled. The halt flag does not remain set,but is cleared
  572. automatically after all current programs have received the request.
  573.  
  574.                 83
  575.  
  576. RX
  577. Usage:RX name[arguments]
  578. This command launches an ARexx program. If the specified name includes an
  579. explicit path,only that directory is searched for the program;otherwise,the
  580. current directory and the system REXX: device are checked for a program with
  581. the given name. The optional argument string is passed to the program.
  582.  
  583. RXSET
  584. Usage:RXSET name value
  585. Adds a(name,value)pair to the Clip List. Name strings are assumed to be in
  586. mixed case. If a pair with the same name already exists,its value is replaced
  587. with the current string. If a name without a value string is given,the entry is
  588. removed from the Clip List.
  589.  
  590. RXC
  591. Usage:RXC
  592. Closes the resident process. The "REXX" public port is withdrawn immediately,
  593. and the resident process exits as soon as the last ARexx program finishes. No
  594. new programs can be launched after a "close" request.
  595.  
  596. TCC
  597. Usage:TCC
  598. Closes the global tracing console as soon as all active programs are no longer
  599. using it. All read read requests queued to the console must be satisfied before
  600. it can be closed.
  601.  
  602. TCO
  603. Usage:TCO
  604. Open the global tracing console. The tracing output from all active programs is
  605. diverted automatically to the new console. The console window can be moved and
  606. resized by the user,and can be closed with the "TCC" command.
  607.  
  608. TE
  609. Usage:TE
  610. Clears the global tracing flag,which forces the tracing mode to OFF for all
  611. active ARexx programs.
  612.  
  613. TS
  614. Usage:TS
  615. Starts interactive tracing by setting the external trace flag,which forces all
  616. active ARexx programs into interactive tracing mode. Programs will start
  617. producing trace output and will pause after the next statement. This command is
  618. useful for regaining control over programs caught in infinite loops or
  619. otherwise misbehaving. The trace flag remains set until cleared by the TE
  620. command,so subsequent program invocations will begin executing in interactive
  621. tracing mode.
  622.  
  623.                 84
  624.  
  625. 9-2 RESOURCE MANAGEMENT
  626.  
  627. Individual ARexx programs manage their internal memory allocation and I/O file
  628. resources,but some resources need to be available to all programs. The
  629. management of these global resources is one of the major functions of the
  630. resident process. Global resources are maintained as doubly-linked lists,in
  631. keeping with the general design principles of the EXEC operating system. Linked
  632. lists provide a flexible and open mechanism for resource management,and help
  633. avoid the built-in limits common with other approaches.
  634.  
  635. THE GLOBAL TRACING CONSOLE
  636.  
  637. The tracing output from an ARexx program usually goes to the standard output
  638. stream STDOUT,and is therefore interleaved with the normal output of the
  639. program. Since this may be confusing at times,a global trace console can be
  640. opened to display only tracing output. The console can be opened using the tco
  641. command utility or be sending an RXTCOPN request packet to the resident
  642. process. ARexx programs will automatically divert their tracing output to the
  643. new window,which is opened as a standard AmigaDOS console. The user can move it
  644. and resize it as required.
  645.  
  646. The tracing console also serves as the input stream for programs during
  647. interactive tracing. When a program pauses for tracing input,the input line
  648. must be entered at the trace console. Any number of programs may use the
  649. tracing console simultaneously,although it is generally recommended that only
  650. one program at a time be traced.
  651.  
  652. The tracing console can be closed using the tcc command or by sending an
  653. RXTCCLS request packet to the resident process. The closing is delayed until
  654. all read requests to the console have been satisfied. Only when all of the
  655. active programs indicate that they are no longer using the console will it
  656. actually be closed.
  657.  
  658. THE LIBRARY LIST
  659.  
  660. The resident process maintains a Library List of the function libraries and
  661. function hosts currently available to ARexx programs. This list is used to
  662. resolve all references to external functions. Each entry has an associated
  663. search priority in the range 100 to -100,with the higher-valued entries being
  664. searched first until the requested function is found. The list is searched by
  665. calling each entry,using the appropriate protocol,until the return code
  666. indicates that the function was found.
  667.  
  668. The two types of entities maintained by the list are quite different in some
  669. respects,but the ultimate way in which a function call is resolved is
  670. transparent to the calling program. A function library is a collection of
  671. functions organized as an Amiga shared library,while a function host is a
  672. separate task that manages a message port. Function libraries are called as
  673. part of the ARexx interpreter's task context,but calls to function hosts are
  674. mediated by passing a message packet. The ARexx resident process is itself a
  675. function host,and is installed in the Library List at a priority of -60.
  676.  
  677. The resident process provides addition and deletion operations for maintaining
  678. the Library List;these operations are performed by sending an appropriate
  679. message packet. The Library List is always maintained in priority order. Within
  680. a given priority level any new entries are added to the end of the chain, so
  681. that entries added first will be searched fist. The priority levels are 
  682.  
  683.                 85
  684.  
  685. significant if any of the libraries have duplicate function name
  686. definitions,since the function located further down the search chain could
  687. never be called.
  688.  
  689. FUNCTION LIBRARIES. Each function library entry in the Library List contains a
  690. library name,a search priority,an entry point offset,and a version number. The
  691. library name must refer to a standard Amiga shared library residing in the
  692. system LIBS: directory so that it can be loaded when needed. Function libraries
  693. can be created and maintained by users or applications developers;Chapter 10
  694. has information on their design and implementation.
  695.  
  696. The "query" function is the library entry point that is actually called by the
  697. interpreter. It must be specified as an integer offset(e.g. "-30")from the
  698. library base. The return code from the query call then indicates whether the
  699. desired function was found;it it was,the function is called with the parameters
  700. passed by the interpreter and the function result is returned to the caller.
  701. Otherwise,the search continues with the next entry in the list. In either event
  702. the library is closed to await the next call.
  703.  
  704. A note of caution: not every Amiga shared library can be used as a function
  705. library. Function libraries must have a special entry point to perform the
  706. dynamic linking required to access the functions from within ARexx. Each
  707. library should include documentation providing its version number and the
  708. integer offset to its "query" entry point.
  709.  
  710. FUNCITON HOSTS. The name associated with a function host is the name of its
  711. public message port. Function calls are passed to the host as a message packet;
  712. it is then up to the individual host to determine whether the specified
  713. function name is one that it recognizes. The name resolution is completely
  714. internal to the host,so function hosts provide a natural gateway mechanism for
  715. implementing remote procedure calls to other machines in a network.
  716.  
  717. THE CLIP LIST
  718.  
  719. The Clip List maintains a set of(name,value)pairs that may be used for a
  720. variety of purposes. Each entry in the list consists of a name and a value
  721. string,and may be located by name. Since the Clip List is publicly accessible,
  722. it may be used as a general clipboard-like mechanism for intertask
  723. communication. In general,the names used should be chosen to be unique to an
  724. application to prevent collisions with other programs. Any number of entries
  725. may be posted to the list.
  726.  
  727. One potential application for the Clip List is as a mechanism for loading
  728. predefined constants into an ARexx program. The language definition does not
  729. include a facility comparable to the "header file" preprocessor in the "C"
  730. language. However,consider a string in the Clip List of the form
  731.  
  732.     pi=3.14159; e=2.718; sqrt2=1.414 ...
  733.  
  734. i.e.,a series of assignments separated by semicolons. In use,such a string
  735. could be retrieved by name using the Built-In function GETCLIP()and then
  736. INTERPRETed within the program. The assignment statements within the string
  737. would then create the required constant definitions. The following program
  738. fragment illustrates the process::
  739.  
  740.                 86
  741.  
  742.     /* assume a string called "numbers" is available*/
  743.     numbers=getclip('numbers')    /* case-sensitive */
  744.     interpret numbers          /* ... assignments*/
  745.     ...
  746.  
  747. More generally,the strings would not be restricted to contain only assignment
  748. statements,but could include any valid ARexx statements. The Clip List could
  749. thus provide a series of programs for initializations or other processing
  750. tasks.
  751.  
  752. The resident process supports addition and deletion operations for maintaining
  753. the Clip List. The names in the(name,value)pairs are assumed to be in mixed
  754. cases,and are maintained to be unique in the list. An attempt to add a string
  755. with an existing name will simply update the value string. The name and value
  756. strings are copied when an entry is posted to the list,so the program that adds
  757. an entry is not required to maintain the strings.
  758.  
  759. Entries posted to the Clip List remain available until explicitly removed. The
  760. Clip List is automatically released when the resident process exits.
  761.  
  762.                 87
  763.  
  764.             CHAPTER 10 INTERFACING TO AREXX
  765.  
  766. This chapter discusses the issues involved in designing and implementing an
  767. interface between ARexx and an external applications program. The material
  768. presented here is directed to software developers,so a high degree of
  769. familiarity with programming the Amiga in either "C" or assembly-language is
  770. assumed.
  771.  
  772. ARexx can interact with external programs in several ways. The command
  773. interface is used to communicate with an external program running as a separate
  774. task in the Amiga's multitasking environment. The interaction takes place by
  775. passing messages between public message ports,and is in many ways similar to
  776. the interaction of a program with Intution,the Amiga's window and menu manager.
  777. The command interface provides both a means of sharing data and a method of
  778. controlling an applications program.
  779.  
  780. Function libraries provide a mechanism for calling external code as part of an
  781. ARexx program's tasks context. The linkages for such calls are established
  782. dynamically at run time rather than when the program is linked,so each function
  783. library must include an entry point to match function names with the address of
  784. the function to be called.
  785.  
  786. Function hosts are external tasks that manage a public message port for
  787. communicating with ARexx or other programs. Both function hosts and function
  788. libraries are managed by the Library List,which provides a prioritized search
  789. mechanism for resolving function names. Function hosts may be used as a gateway
  790. into a metwork to provide a remote procedure call facility. ARexx imposes no
  791. constraints on the internal operations of a function host,except to require
  792. that message packets be returned with an appropriate code.
  793.  
  794. The resident process acts as the hub for communications between ARexx and
  795. external entities. It opens and manages a public message port named "REXX," and
  796. provides a number of support services. Note that the resident process is itself
  797. a "host application" whose function it is to launch ARexx programs and maintain
  798. global resources. The activation structures for all ARexx programs are linked
  799. into a list maintained by the resident process,and in principle their compete
  800. internal states are accessible to external programs.
  801.  
  802. The ARexx interpreter is structured as an Amiga shared library and includes
  803. entry points specifically designed to help implement an interface to ARexx.
  804. Functions are available to create and delete message packets,argument
  805. strings,and other resources. Software developers are rged to use these library
  806. routines whenever possible,as they provide "safe" access to the internal
  807. structures. The ARexx Systems Library functions are documented in Appendix C.
  808. The distribution disk contains the INCLUDE files required to required to work
  809. with the library and data structures.
  810.  
  811.                 89
  812.  
  813. 10-1 BASIC STRUCTURES
  814.  
  815. Most developers will need to work with only two of the data structures used by
  816. ARexx. The RexxArg structure is used for all of the strings manipulated by the
  817. interpreter. It is usually passed as an argstring,a pointer offset from the
  818. structure base that may be treated like an ordinary string pointer. The RexxMsg
  819. structure is an extension of an EXEC Message,and is the message packet used for
  820. all communications with external programs.
  821.  
  822. ARGSTRINGS. All ARexx strings are maintained as RexxArg structures,which are
  823. diagrammed in Table 10.1 below. Note that his actually a variable-length
  824. structure allocated for each specific string length. String parameters are sent
  825. in the form of argstrings,a pointer to the string buffer area of the RexxArg
  826. structure. The string in the stucture is always given a trailing null byte,so
  827. that external programs can treat argstrings like a pointer to a null-terminated
  828. string. Additional data about the string(its length,hash code,and attributes)
  829. are available at negative offsets from the argstring pointer.
  830.  
  831.             Table 10.1 The RexxArg Structure
  832.  
  833.         STRUCTURE RexxArg,0
  834.         LONG    ra_Size        ; allocated length
  835.         UWORD    ra_Length    ; length of string
  836.         UBYTE    ra_Flags    ; attribute flags
  837.         UBYTE    ra_Hash        ; hash code
  838.         STRUCT    ra_Buff,8    ; buffer (argstring points here)
  839.  
  840. Library functions are available to create and delete argstrings,and for
  841. converting integers into argstring format. The function CreateArgstring()
  842. allocates a structure and copies a string into it,and returns an argstring
  843. pointer to the structure. The function DeleteArgstring()can be used to release
  844. an argstring when it is no longer needed.
  845.  
  846. MESSAGE PACKETS. All communications between ARexx and external programs are
  847. mediated with with message packets,whose structure is diagrammed in Table 10.2
  848. below. Functions are provided in the ARexx Systems Library to create,
  849. initialize,and delete these message packets. Each packet sent from ARexx to an
  850. external program is marked with a special pointer in its name field. This can
  851. be used to distinguish the message packets from those belonging to other
  852. programs,in case a message port is being shared.
  853.  
  854. Message packets are created using the CreateRexxMsg()function,and can be
  855. released using the DeleteRexxMsg(). Note that the message packets passed by
  856. ARexx to a host application(as a command,for instance)are identical to the
  857. packets the host would use to invoke an ARexx program. This commonality of
  858. design means that only one set of functions is needed to create and delete
  859. message packets,and that external programs can use the same routines that the
  860. interpreter uses to handle the packets.
  861.  
  862. RESOURCE NODES. A somewhat higher-level data structure called a "resource node"
  863. (a RexxRsrc structure)is used extensively within ARexx to maintain resource
  864. lists. These nodes are variable-length structures that include the total
  865. allocated length as a field within the node,and that also provide for an
  866. "auto-delete" function. This latter capability allows the address of a clean-up
  867.  
  868.                 90
  869.  
  870. function to be associated with the node so that an entire(possibly
  871. inhomogeneous)list of resource nodes can be deallocated with a single function
  872. call.
  873.  
  874.             Table 10.2 The RexxMsg Structures
  875.  
  876.         STRUCTURE RexxMsg,MN_SIZE
  877.         APTR    rm_TaskBlock    ; global pointer
  878.         APTR    rm_LibBase    ; library pointer
  879.         LONG    rm_Action    ; command code
  880.         LONG    rm_Result1    ; primary result
  881.         LONG    rm_Result2    ; secondary result
  882.         STRUCT    rm_Args,16*4    ; arguments (ARGO-ARG15)
  883.                      ;  the extension area
  884.         APTR    rm_PassPort    ; forwarding port
  885.         APTR    rm_CommAddr    ; host address
  886.         APTR    rm_FileExt    ; file extention
  887.         LONG    rm_Stdin    ; input stream
  888.         LONG    rm_Stdout    ; output steam
  889.         LONG    rm_avail    ; reserved
  890.         LABEL    rm_SIZEOF    ; 128 bytes
  891.  
  892. 10-2 DESIGNING A COMMAND INTERFACE
  893.  
  894. The minimal command interface between ARexx and an applications program
  895. requires only a public message port and a routine to process the commands
  896. received. For most host applications this will require little extra machinery,
  897. as the program will probably already have several message ports for key and
  898. menu events,timer messages,and so on. Processing the command strings should be
  899. relatively straightforward for command-oriented applications. Hosts that are
  900. entirely menu-driven will require somewhat more additional programming,unless
  901. commands are supported only as simulated menu events. The specific choice of
  902. which commands to support is always left up to the applications designer,as
  903. ARexx imposes no restrictions on the structure of the commands that can be
  904. issued.
  905.  
  906. The basic sequence of events in the command interface begins when the host
  907. sends a command invocation message to the ARexx resident process. This is
  908. usually in response primitives supported by the host. When the resident process
  909. receives the message packet,it spawns a new DOS process the run the macro
  910. program. The command line is parsed to extract the command token(the first
  911. word),and the interpreter searches for a file that matches the command name.
  912.  
  913. Once a macro program file has been found,it is executed by the interpreter and
  914. (usually)results in one or more commands being issued back to the host
  915. application's public port. The macro program waits while each command is
  916. processed by the host,and takes appropriate actions if the return code
  917. indicates that an error occurred. Eventually the macro program finishes and
  918. returns the invocation message packet back to the host.
  919.  
  920. Error handling is an important consideration in the interface design. Macro
  921. programs must receive return codes so that processing actions can be altered
  922. when errors occur.
  923.  
  924.                 91
  925.  
  926. Normally,the host application should not return a message packet until the
  927. command has been processed and its error status in known. Hosts that support
  928. two streams of commands(from the user and from the command interface)will need
  929. a flag to indicate the source of each command. Errors in user commands might
  930. normally be reported on the screen,but errors in ARexx commands must be
  931. reported by setting the result field in the message packet.
  932.  
  933. Return codes should generally be chosen to follow the model of an error
  934. severity level,with small integers representing relatively harmless conditions
  935. and larger values indicating progressively more severe errors. This will allow
  936. a characteristic failure level to be established within a macro program,so that
  937. insignificant errors can be ignored. The choice of the specific return code
  938. values is left to the applications designer.
  939.  
  940. RECEIVING COMMAND MESSAGES
  941.  
  942. Each host application must open a public message port to support the command
  943. interface. When a macro program issues a command to the host,a message packet
  944. containing the command is sent to this public port. The structure of these
  945. message packets is shown in Table 10.2. The rm_Action field will be set to
  946. RXCOMM,and the ARGO parameter slot will contain the command as an argstring
  947. pointer. Parameter slots ARG1-ARG15 are not used for command messages. Two
  948. other fields are potentially of interest: the rm_RexxTask field contains a
  949. pointer to the global data structure for the program that issued the command,
  950. and the rm_LibBase field has the ARexx library base address. The fields in the
  951. extension area may also be of interest to the host program;these are described
  952. later on. Except for setting the result fields rm_Result1 and rm_Result2,the
  953. host application should not alter the message packet.
  954.  
  955. RESULT FIELDS
  956.  
  957. When the host program finishes processing the command,it must set the primary
  958. result field rm_Result1 to an error severity level or zero if no errors
  959. occurred. This is the field which will be assigned to the special variable RC
  960. in the macro program. The secondary result field rm_Result2 should be set to
  961. zero unless a result string(as described below)is being returned. The packet
  962. can then be returned to the sender using the EXEC function ReplyMsg().
  963.  
  964. In some cases a macro program may request a result string by setting the
  965. RXFB_RESULT modifier bit in the command code. If possible,the host application
  966. should then return the result as an argstring pointer in the secondary result
  967. field rm-Result2. A result string should only be returned if explicitly
  968. requested and if no errors occurred during the call(rm_Result1 set to zero).
  969. Failure to observe these rules will result either in memory loss or in
  970. corruption of the system free-memory list.
  971.  
  972. MULTIPLE HOST PROCESSES
  973.  
  974. Many applications programs support concurrent activities on several sets of
  975. data. For example,most text editors allow several files to be edited at once. A
  976. command issued from a particular instance of the editor might invoke an ARexx
  977. macro program,so clearly any commands issued from that macro would have to be
  978. directed to the correct instance of the editor. ARexx provides for this by
  979.  
  980.                 92
  981.  
  982. allowing the applications program to declare an initial host address when a
  983. program is invoked. A separate message port would be opened for each instance
  984. of the host application,and this port would be named as the initial host
  985. address for all invocations from that instance. In the example above,if the
  986. editor opened two ports named "MyEdit1" and "MyEdit2,"then programs invoked by
  987. the "MyEdit1" instance would send commands back to the "MyEdit1" port.
  988.  
  989. MULTIPLE MESSAGE PORTS. Host applications are not limited to having a single
  990. message port for commands. If several different kinds of commands are to be
  991. received,it might be appropriate to set up more than one port. Macro programs
  992. would then use the ADDRESS instruction to direct commands to the appropriate
  993. port. The different ports could be used simultaneously,since ARexx programs
  994. execute as separate tasks.
  995.  
  996. 10-3 INVOKING AREXX PROGRAMS
  997.  
  998. ARexx programs are invoked by sending a message packet to the resident process.
  999. Programs may be invoked as either a command or as a function. The command mode
  1000. of invocation is generally simpler,as it requires setting only a few fields in
  1001. the message packet.
  1002.  
  1003. MESSAGE PACKETS
  1004.  
  1005. The structure of the message packet supported by ARexx is shown in Table 10.2.
  1006. This structure provides fields for passing arguments and for specifying
  1007. overrides to various internal defaults. The packets are cleared(set to 0)when
  1008. allocated,and the client-supplied fields are never altered by ARexx. Message
  1009. packets can be reused after being returned,and generally only one is required.
  1010.  
  1011. COMMAND(ACTION)CODE. The rm_Action field of the message packet determines the
  1012. mode of invocation. It can be set to either RXCOMM or RXFUNC for command or
  1013. function mode,respectively. Several modifier flags can be used with the command
  1014. code;these are described later in this chapter.
  1015.  
  1016. ARGUMENT STRINGS. Command strings,function names,and argument strings must be
  1017. supplied as argstrings. Strings can be conveniently packaged into argstrings
  1018. using the CreateArgstring()library function,which takes a string pointer and a
  1019. length as its arguments. Argstrings point to a null-terminated string and may
  1020. be treated like an ordinary string pointer in most cases. In principle,a host
  1021. application could build the argstrings directly,but since the strings must
  1022. remain unchanged for the duration of a ARexx program,the host might need to
  1023. maintain many such structures.
  1024.  
  1025. The argstrng pointer returned by CreateArgstring()is installed in the
  1026. appropriate parameter slot of the message package:ARGO for the command string
  1027. or function name,and ARG1-ARG15 for argument strings. Argstrings can be
  1028. recycled after a packet has returned by calling the DeleteArgstring() function.
  1029.  
  1030. SENDING THE PACKET. Once the required fields have been filled in,the host
  1031. application can send the packet to the "REXX" public port using the EXEC
  1032. function PutMsg(). The address of the "REXX" port can be obtained by a call to
  1033. the FindPort()function,but this address should not be cached internally,since
  1034. the port could close at any time. To be absolutely safe,the calls to FindPort()
  1035. and PutMsg()should be bracketed by calls to the EXEC routines Forbid()and
  1036. Permit(). This will exclude the slight possibility that the message port could
  1037. close in the few microseconds before the message packet is actually sent to the
  1038. port address.
  1039.  
  1040. After sending the packet the host can return to its normal processing,since the
  1041. macro program will execute as a separate task. In most cases it will be
  1042. advisable to "lock-out" further user commands while the ARexx program is
  1043. running,to preserve te integrity of any shared data structures that may be
  1044. accessed externally.
  1045.  
  1046. COMMAND INVOCATIONS
  1047.  
  1048. In the command mode of invocation the host supplies a command string consisting
  1049. of a name token followed by an argument string. ARexx parses the string to
  1050. extract the command name,which is usually the name of a program file. The
  1051. default action is to use the remainder of the command string as the(single)
  1052. argument string for the program. This may be overridden by requesting command
  1053. tokenization,which is done by setting the RXFB_TOKEN modifier flag in the
  1054. action code of the message packet. In this case the entire command string will
  1055. be parsed,and the program may have many argument strings.(There is no limit to
  1056. the number of arguments that may be derived from the command string,since they
  1057. don't have to fit into the parameter slots of the message packet.)
  1058.  
  1059. The parsing process uses "white space" (blanks,tabs,etc.)as the token
  1060. separators,and has a several special features.
  1061.  
  1062. QUOTING CONVENTION. Either single(')or double(")quotes may be used to surround
  1063. items that include "white space" and would otherwise be separated during
  1064. parsing. Single quotes may appear within a double-quote-delimited token,and
  1065. vice versa;however,double-delimiter sequences are not accepted. The quotes are
  1066. removed from the parsed token. An "implicit" quote at the end of the string is
  1067. also recognized. If the command string ends before the closing delimiter has
  1068. been found,the null byte is accepted as the final delimiter. For example,
  1069.     look.rexx "Now is the time" "can't ou see
  1070.  
  1071. is a command with the two arguments strings "Now is the time" and "can't you
  1072. see"(but without the quotes.)
  1073.  
  1074. STRING FILES. If the command name(the first token of the string)is quoted,it is
  1075. assumed to be a "string file" --an ARexx program in a string,rather than the
  1076. name of a disk file. This is a convenient way to run very brief programs,
  1077. although programs of any length may be stored this way. If command tokenization
  1078. has not been specified,the remainder of the string is not scanned and no quote
  1079. characters are removed. In this case the quoting convention isuseful only for
  1080. indicating "string file" programs. The entire command string can be declared as
  1081. a "string file" by setting the RXFB_STRING modifier flag of the action code.
  1082. When this flag is set,no parsing at all is applied to the command.
  1083.  
  1084. RESULT STRING. Command invocations do not usually request a result string,but
  1085. can do so by setting the RXFB_RESULT modifier flag. The host application must
  1086. be prepared to recycle the returned result string once it is no longer needed.
  1087.  
  1088.                 94
  1089.  
  1090. FUNCTION INVOCATIONS
  1091.  
  1092. In a function invocation the host application supplies a function name string
  1093. and from 0 to 15 argument strings. The name string is used to locate an
  1094. external program file and may include directory specifiers and a file
  1095. extension. The actual argument count(not including the name string)must be
  1096. placed in the low-order byte of the command code.
  1097.  
  1098. This mode of invocation is normally used when a result string is expected and
  1099. the argument strings are conveniently available. Note that a result does not
  1100. have to be requested,however.
  1101.  
  1102. RESULT STRINGS. Function invocations request a result string by setting the
  1103. RXFB_RESULT modifier flag bit. If no errors occurred and a result string was
  1104. requested,the secondary result field in the returned packet will be a pointer
  1105. to the result string. However,if the program exited without supplying a result,
  1106. the secondary field will be zero.
  1107.  
  1108. STRING FILES. The function name argument may specify a "string file" rather
  1109. than the name of a filing system object. This is indicated by setting the
  1110. RXFB_STRING modifier flag.
  1111.  
  1112. SEARCH ORDER
  1113.  
  1114. The search for a program file matching a command or function name is normaly a
  1115. two-step process. For each directory to be checked,a search is made first with
  1116. the current file extension appended to the name string. If this search fails,
  1117. the second search uses the unmodified name string. The first step is skipped if
  1118. the command or function name includes an explicit file extension.
  1119.  
  1120. The default file extension is ".rexx,"but this can be changed by supplying a
  1121. file extension string in an extended message packet. Host applications will
  1122. usually specify a file extension,since it provides a convenient way to
  1123. distinguish the macro programs that are specific to that application. Refer to
  1124. the section on Extension Fields for further details.
  1125.  
  1126. The search path for a program depends on the way the program name was
  1127. specified. If an explicit device or directory specification precedes the
  1128. program name,only that directory will be searched. For example,the command-
  1129. level invocation of "rx df0:s/test" will search only the df0:s directory for a
  1130. file named test.rexx or test. If the program name does not include a path,the
  1131. search path begins with the current directory and proceeds to the system REXX:
  1132. directory. To further the above example,invoking the program as "rx test 1 2 3"
  1133. would search for the files test.rexx,test,REXX:test.rexx,and REXX:test,in that
  1134. order.
  1135.  
  1136. If an ARexx program cannot be found,one alternative action may be taken. If the
  1137. rm_PassPort field of an extended packet was supplied,the message packet is
  1138. passed along to that port,which might be the next process in a search chain.
  1139. Otherwise the message is returned with a "Program not found"error indication
  1140. (error code 1.)
  1141.  
  1142.                 95
  1143.  
  1144. EXTENSION FIELDS
  1145.  
  1146. The RexxMsg structure includes several "extension fields" that can be used to
  1147. override various defaults when a program is invoked. These extension fields can
  1148. be filled in selectively,and only the non-zero values will override the
  1149. corresponding default. ARexx never modifies the extension area.
  1150.  
  1151. Host applications should supply values for the file extension and host address
  1152. fields of the message packet. The file extension affects which program files
  1153. will match a given command name,and allows macro programs specific to the host
  1154. to be given distinctive names. The host address must refer to a public message
  1155. port,and will usually indicate the host's own port. Any appropriate(but usually
  1156. short)strings can be chosen for these values. Oftern,the name of the
  1157. applications program itself can be used as its host address and file extension.
  1158.  
  1159. PASSPORT. The rm_PassPort field allows the search for a program to be "passed
  1160. along" to another messsage port after checking for an ARexx program. If the
  1161. command or function name doesn't resolve to an ARexx program,the message packet
  1162. is forwarded to the message port specified as the PassPort. This allows
  1163. applications to maintain control over the search order for external program
  1164. files.
  1165.  
  1166. Note that the rm_PassPort field must be the actual address of a message port,
  1167. rather than a name string. The PassPort therefore does not have a public port,
  1168. but the port should be a secured resource,since the message is sent directly to
  1169. this address without checking to see whether it is a valid message port.
  1170.  
  1171. HOST ADDRESS. The rm_ComAddr field overrides the default initial host address,
  1172. which is "REXX." The host address is the name of the messsage port to which
  1173. commands will be directed,and is supplied as a pointer to a null-terminated
  1174. string. Applications that support multiple instances of user data will usually
  1175. create a separate message port for each instance. The name of this port would
  1176. then be supplied as the host address for any commands issued from that
  1177. instance.
  1178.  
  1179. FILE EXTENSION. The rm_FileExt field is used to override the default file
  1180. extension for ARexx programs,which is "REXX". Host applications can use the
  1181. file extension to distinguish the names of the macro programs specific to that
  1182. application. It is supplied as a pointer to a null-terminated string.
  1183.  
  1184. INPUT AND OUTPUT STREAMS. The default input and output steams for an ARexx
  1185. program are inherited from the host application's process structure,if the host
  1186. is a process rather than just a task. One or both of these streams may be
  1187. overridden by supplying an appropriate value in the rm-Stdin or rm_stdout
  1188. fields. The values supplied must be valid DOS filehandles,and must not be
  1189. closed while the program is executing. The steams are installed directly into
  1190. the program's process structure,replacing the prior values.
  1191.  
  1192. The output stream is also used as the default tracing stream for the program.
  1193. If interactive tracing is to be used in a program,the output stream should
  1194. refer to a console device,since it will be used for input as well.
  1195.  
  1196.                 96
  1197.  
  1198. In the event than an ARexx program is invoked by an EXEC task,rather than by an
  1199. DOS process,the extension field streams are the only way that the launched
  1200. program can be given default I/O streams.
  1201.  
  1202. INTERPRETING THE RESULT FIELDS
  1203.  
  1204. The message packet that invoked an ARexx program is returned to the client when
  1205. the program finishes. The two result fields will contain error codes or
  1206. possibly a result string. The interpretation of the result fields depends
  1207. partly on the mode of invocation. If the primary result field rm_Result1 is
  1208. zero,the program executed normally and the secondary field rm_Result2 will
  1209. contain a pointer to a result string,assuming that one was requested(and
  1210. available.)
  1211.  
  1212. If the primary result is non-zero,it represents either an error severity level
  1213. or else the return code from a command invocation. The two cases can be
  1214. distinguished by examining the secondary result. If the secondary field is also
  1215. non-zero,an error occurred and the secondary field is an ARexx error code. If
  1216. the secondary result is zero,then the primary result is the return code passed
  1217. by an "EXIT rc" or "RETURN rc" instruction in the program. The application
  1218. program can use this return code either as an error indication or to initiate
  1219. some particular processing action.
  1220.  
  1221. Result strings are always returned as an argstring and become the property(that
  1222. is,responsibility)of the host. When the string is no longer needed,it can be
  1223. released using the DelArgstring() function.
  1224.  
  1225. Errors occurring in macro programs should usually be reported to the user.
  1226. Explanatory messages are available for all ARexx error codes,and can be
  1227. obtained by calling the ARexx Systems Library function ErrorMsg().
  1228.  
  1229. 10-4 COMMUNICATING WITH THE RESIDENT PROCESS
  1230.  
  1231. All communications with the resident process are handled by passing message
  1232. packets,which were previously diagrammed in Table 10.2. The packet has a
  1233. command field that describes the action to be performed and parameter fields
  1234. that are specific to the command. Message packets are processed as they are
  1235. received,and are then either returned to the sender or passed along to another
  1236. process(in the case of a program invocation.) The packet includes two result
  1237. fields that are used to return error codes or result strings. The parameter
  1238. fields of the message packet may contain either(long)integer values or pointers
  1239. to argument strings. String arguments are assumed to be argstring pointers
  1240. unless otherwise specified.
  1241.  
  1242. COMMAND(ACTION)CODES
  1243.  
  1244. The command codes that are currently implemented in the resident process are
  1245. described below. Commands are listed by their mnemonic codes,followed by the
  1246. valid modifier flags. The final code value is always the logical OR of the code
  1247. value and all of the modifier flags selected. The command code is installed in
  1248. the rm_Action field of the message packet.
  1249.  
  1250. USAGE: RXADDCON [RXFB_NONRET]
  1251. This code specifies an entry to be added to the Clip List. Parameter slot ARGO
  1252. points to the name string,slot ARG1 points to the value string,and slot ARG2
  1253. contains the length of the value string.
  1254.  
  1255.                 97
  1256.  
  1257. The name and value arguments do not need to be argstrings,but can be just
  1258. pointers to storage areas. The name should be a null-terminated string,but the
  1259. value can contain arbitrary data including nulls.
  1260.  
  1261. USAGE: RXADDFH [RSFB_NONRET]
  1262. This action code specifies a function host to be added to the Library List.
  1263. Parameter slot ARGO points to the(null-terminated)host name string,and slot
  1264. ARG1 holds the search priority for the node. The search priority should be an
  1265. integer between 100 and -100 inclusive;the remaining priority ranges are
  1266. reserved for future extensions. If a none already exists with the same name,the
  1267. packet is returned with a warning level error code. Note that no test is made
  1268. at this time as to whether the host port exists.
  1269.  
  1270. USAGE:RXADDLIB [RXFB_NONRET]
  1271. This code specifies an entry to be added to the Library List. Parameter slot
  1272. ARGO points to a null-terminated name string referring either to a function
  1273. library or a function host. Slot ARG1 is the priority for the node and should
  1274. be an integer between 100 and -100 inclusive;the remaining priority ranges are
  1275. reserved for future extensions. Slot ARG2 contains the entry oint offset and
  1276. slot ARG3 is the library version number. If a node already exists with the same
  1277. name,the packet is returned with a warning level error code. Otherwise,a new
  1278. entry is added and the library or host becomes available to ARexx programs.
  1279. Note that no test is made at this time as to whether the library exists and can
  1280. be opened.
  1281.  
  1282. USAGE:RXCOMM [RXFB_TOKEN] [RXFB_STRING] [RXFB_RESULT] [RXFB_NOIO]
  1283. Specifies a command-mode invocation of an ARexx program. Parameter slot ARGO
  1284. must contain an argstring ointer to the command string. The RXFB_TOKEN flag
  1285. specifies that the command line is to be tokenized before being passed to the
  1286. invoked program. The RXFB_STRING flag bit indicates that the command string is
  1287. a "string file." Command invocations do not normally return result strings,but
  1288. the RXFB_RESULT flag can be set if the caller is prepared to handle the cleanup
  1289. associated with a returned string. The RXFB_NOIO modifier suppresses the
  1290. inheritance of the host's input and output streams.
  1291.  
  1292. USAGE:RXFUNC [RXFB_RESULT] [RXFB_STRING] [RXFB_NOIO] argcount
  1293. This command code specifies a function invoction. Parameter slot ARGO contains
  1294. a pointer to the function name string,and slots ARG1 through ARG15 point to the
  1295. argument strings,all of which must be passed as argstrings. The lower byte of
  1296. the command code is the argument count;this count excludes the function name
  1297. string itself. Function calls normally set the RXFB_RESULT flag,but this is not
  1298. mandatory. The RXFB_STRING modifier indicates that the function name string is
  1299. actually a "string file". The RXFB_NOIO modifier suppresses the inheritance of
  1300. the host's input and output streams.
  1301.  
  1302. USAGE:RXREMCON [RXFB_NONRET]
  1303. This code requests that an entry be removed from the Clip List. Parameter slot
  1304. ARGO points to the null-terminated name to be removed. The Clip List is
  1305. searched for a node matching the supplied name,and if a match is found the list
  1306. node is removed and recycled. If no match is found the packet is returned with
  1307. a warning error code.
  1308.  
  1309. USAGE:RXREMLIB [RXFB_NONRET]
  1310. This command removes a Library List entry. Parameter slot ARGO points to the
  1311. null terminated string specifying the library to be removed. The Library List
  1312. is searched for a node matching the library name,and if a match is found the
  1313.  
  1314.                 98
  1315.  
  1316. node is removed and released. If no match is found the packet is returned with
  1317. a warning error code. The libary node will not be removed if the library is
  1318. currently being used by an ARexx program.
  1319.  
  1320. USAGE:RXTCCLS [RXFB_NONRET]
  1321. This code requests that the global tracing console be closed. The console
  1322. window will be closed immediately unless one or more ARexx programs are waiting
  1323. for input from the console. In this event,the window will be closed as soon as
  1324. the active programs are no longer using it.
  1325.  
  1326. USAGE:RXTCOPN [RXFB_NONRET]
  1327. This command requests that the global tracing console be opened. Once the
  1328. console is open,all active ARexx programs will divert their tracing output to
  1329. the console. Tracing input(for interactive debugging)will also be diverted to
  1330. the new console. Only one console can be opened;subsequent RXTCOPN requests
  1331. will be returned with a warning error message.
  1332.  
  1333. MODIFIER FLAGS
  1334.  
  1335. Command codes may include modifier flags to select various processing options.
  1336. Modifier flags are specific to certain commands,and are ignored otherwise.
  1337.  
  1338. RXFB_NOIO. This modifier is used with the RXCOMM and RXFUNC command codes to
  1339. suppress the automatic inheritance of the host's input and output streams.
  1340.  
  1341. RXFB_NONRET. Specifies that the message packet is to be recycled by the
  1342. resident process rather than being returned to the sender. This implies that
  1343. the sender doesn't care about whether the requested action succeeded,since the
  1344. returned packet provides the only means of acknowledgement. Messge packets are
  1345. released using the library function DeleteRexxMsg().
  1346.  
  1347. RXFB_RESULT. This modifer is valid with the RXCOMM and RXFUNC commands,and
  1348. requests that the called program return a result string. If the program
  1349. EXITs(or RETURNs)with an expression,the expression result is returned to the
  1350. caller as an argstring. It is then the caller's responsibility to release the
  1351. argstring when it is no longer needed;this can be done using the library
  1352. function DeleteArgstring().
  1353.  
  1354. RXFB_STRING. This modifer is valid with the RXCOMM and RXFUNC command codes. It
  1355. indicates that the command or function argument(in slot ARGO)is a "string file"
  1356. rahter than a file name.
  1357.  
  1358. RXFB_TOKEN. This flag is used with the RXCOMM code to request that the command
  1359. string be completely tokenized before being passed to the invoked program.
  1360. Programs invoked as commands normally have only a single argument string. The
  1361. tokenization process uses "white space" to separate the tokens,except within
  1362. quoted strings. Quoted strings can use either single or double quotes,and the
  1363. end of the command string(a null character)is considered as an implicit closing
  1364. quote.
  1365.  
  1366.                 99
  1367.  
  1368. RESULT FIELDS
  1369.  
  1370. The resident process uses the standard command-level conventions for the
  1371. primary return code installed in rm_Result1. Minor or warning errors are
  1372. indicated by a value of 5,and more serious errors are returned as values of 10
  1373. or 20. The secondary result field rm-Result2 will either be zero or an ARexx
  1374. error code if applicable.
  1375.  
  1376. Note that RXCOMM and RXFUNC messages are returned directly by the invoked macro
  1377. program,rathe than by the residen process.
  1378.  
  1379. 10-5 EXTERNAL FUNCTION LIBRARIES
  1380.  
  1381. ARexx supports external function libraries as a mechanism for user-defined
  1382. extensions to the language. Function libraries may be written and maintained by
  1383. users or applications developers.
  1384.  
  1385. DESIGN CONSIDERATIONS
  1386.  
  1387. There are several different purposes for which a function library might be
  1388. designed. In the simplest case,a library could be used to extend the string
  1389. manipulation or mathematical capabilities of the language by defining new
  1390. functions. Such a library could be entirely self-contained or might call other
  1391. system libraries to perform specific operations.
  1392.  
  1393. Another alternative would be to build a library that interacts closely with an
  1394. external applications program. This could allow specific operations in the host
  1395. application to be performed as function calls rather than as commands. There
  1396. are several advantages to this approach,as it avoids the need to parse command
  1397. strings and does not require the multiple task context changes associated with
  1398. message-passing. The library might include entry points for specific operaions
  1399. as well as functions to support processing required by the applications
  1400. program.
  1401.  
  1402. Function libraries can also serve as bridges to other system or applications
  1403. libraries. For example,if a program needed to call the functions in a graphics
  1404. library,a bridge library could be built to match the function names in the
  1405. program with the appropriate entry point in the graphics library. A related
  1406. possibility would be to use ARexx as a test driver for a program under
  1407. development. Once the query table and parameter passing mechanisms for the
  1408. function library have been built,new routines under development could be tested
  1409. by just adding a table entry. Since building test programs is ofter very time-
  1410. consuming,the flexibility and interactive debugging capabilities of ARexx make
  1411. it an attractive alternative to compiled languages like "C."
  1412.  
  1413. Regardless of the intended application,all function libraries share a common
  1414. structure. The initial design follows that of the standard EXEC shared library,
  1415. with the three required entry points Open,Close,and Expunge,plus a reserved
  1416. slot. The library must also have a "query" entry point,which serves to match
  1417. the name supplied by ARexx with the intended function. Typically,this will
  1418. consist of a table of function names and a routine to search for the specified
  1419. one.
  1420.  
  1421. REENTRANCY. Functions libraries should be designed to be fully reentrant,since
  1422. any number of ARexx programs may be running at any time. If this is not
  1423. feasible due to other design constraints,the query function should include a
  1424. lockout mechanism to prevent multiple calls to the library routines.
  1425.  
  1426.                 100
  1427.  
  1428. CALLING CONVENTION
  1429.  
  1430. The library's query function will be called from the interpreter's context with
  1431. the address of a message packet in register A0 and the library base in A6. The
  1432. structure of the message packet is the same as that in Table 10.2,but note that
  1433. although a message packet is used to carry the arguments,it is not queued at a
  1434. message port and does not need to be unlinked. The name of the function to be
  1435. called is carried in the ARGO parameter slot. The query function must search
  1436. for this function name and,if the name cannot be found,must return an error
  1437. code of 1("Program not found")in register D0. The library will then be closed
  1438. and the search continued in the next function library. The query function
  1439. should not modify any fields within the message packet,as it must be passed
  1440. along to the next library until the function is located.
  1441.  
  1442. PARAMETER CONVERSION
  1443.  
  1444. Once the requested function has been found,the query funcion may need to
  1445. transform the parameters passed by ARexx into the form expected by the
  1446. function. Whether the parameter strings need to be converted depends on how
  1447. they are to be used. In some cases it may be sufficient just to foward a
  1448. pointer to the message packet to the called function,while in other cases the
  1449. query function may need to load parameters into registers or to perform
  1450. conversion operations. The parameters in ARG1-ARG15 are always passed as
  1451. argstrings,and may be treated like a pointer to a null-terminated string.
  1452. Further attributes are stored at negative offsets from the argstring pointer,
  1453. and may be helpful in working with the string.
  1454.  
  1455. Numeric quantities are passed as strings of ASCII characters and will need to
  1456. be converted to integer or floating-point format if arithmetic calculations are
  1457. to be performed. The ARexx System Library includes a limited set of functions
  1458. to do parameter conversions.
  1459.  
  1460. The actual parameter count can be obtained from the low-order byte of the
  1461. rm_Action field in the message packet. The count never includes the function
  1462. name itself(in ARGO),but does include arguments specified as "defaults." Such
  1463. arguments will have a zero value in the corresponding parameter slot.
  1464.  
  1465. Note that the parameter block of the message packet,containing the fields
  1466. ARG0-ARG15,is structured like the argument array expected by the main(argc,
  1467. argv)function of a "C" program. This suggests a simple way that a function
  1468. library could provide a bridge to a series of "C" programs. The query function
  1469. would need only to determine the address of the called function,and then push
  1470. the parameter block address and argument count onto the program stack.
  1471.  
  1472. RETURNED VALUES
  1473.  
  1474. Each library function must return an error code and a value string. The error
  1475. code is returned in register D0,and should be 0 if no errors occurred. The
  1476. value string must be returned as an argstring pointer in register A1,unless D0
  1477. indicates that an error occurred during the call. The mechanisms for creating
  1478. the proper return values can be made part of the query function,so that all
  1479. functions in the library share a common return path.
  1480.  
  1481.                 101
  1482.  
  1483. 10-6 DIRECT MANIPULATION OF DATA STRUCTURES
  1484.  
  1485. All of the data structures maintained by the resident process are built into
  1486. the ARexx Systems Library base and are therefore accessible to external
  1487. programs. The Task List in the RexxBase structure links the global data
  1488. structures for all currently active ARexx programs. This linkage uses the node
  1489. contained in the message port of the RexxTask structure,rather than at the head
  1490. of the structure. The RexxTask structure is the global data structure and
  1491. initial storage environment for the ARexx program,and all descendant storage
  1492. environments are linked into the Environment List. The linkage of internal data
  1493. structures is such that the complete internal state of all ARexx programs can
  1494. be reached starting from the library base pointer.
  1495.  
  1496. Two library functions,LockRexxBase() and UnlockRexxBase(),are provided to
  1497. mediate access to the global structures. The structure base should be locked
  1498. before reading any of the data items or traversing any of the lists. The
  1499. present version of these functions provides only a global lock,but future
  1500. extensions will allow individual resources to be locked.
  1501.  
  1502. In general it should not be necessary to manipulate directly any of these data
  1503. structures. Functions have been provided in the ARexx Systems Library to
  1504. perform all of the operations required to interface external program to the
  1505. ARexx system. It is therefore recommended that applictions developers avoid
  1506. using any of the internal structures except as provided through the library
  1507. functions.
  1508.  
  1509.                 102
  1510.  
  1511.             APPENDIX A ERROR MESSAGES
  1512.  
  1513. When the ARexx interpeter detects an error in a program,it returns an error
  1514. code to indicate the nature of the problem. Errors are normally handled by
  1515. displaying the error code,the source line number where the error occurred,and a
  1516. brief message explaining the error condition. Unless the SYNTAX interrupt has
  1517. been previously enabled(using the SIGNAL instruction),the program then
  1518. terminates and control returns to the caller. Most syntax and execution errors
  1519. can be trapped by the SYNTAX interrupt,allowing the user to retain control and
  1520. perform whatever special error processing is required. Certain errors are
  1521. generated outside of the context of an ARexx program,and therefore cannot be
  1522. trapped by this mechanism. Refer to chapter 7 for further information on error
  1523. trapping and processing.
  1524.  
  1525. Associated with each error code is a severity level that is reported to the
  1526. calling program as the primary result code. The error code itself is returned
  1527. as the secondary result. The subsequent propagation or reporting of these codes
  1528. is of course dependent on the external(calling)program.
  1529.  
  1530. The following pages list all of the currently-defined error codes,along with
  1531. the associated severity level and message string.
  1532.  
  1533. ERROR: 1 SEVERITY: 5 MESSGE: PROGRAM NOT FOUND
  1534. The named program could not be found,or was not an ARexx program. ARexx
  1535. programs are expected to start with a "/*" sequence. This error is detected by
  1536. the external interface and cannot be trapped by the SYNTAX interrupt.
  1537.  
  1538. ERROR: 2 SEVERITY: 10 MESSAGE: EXECUTION HALTED
  1539. A control-C break or an external half request was received and the program
  1540. terminated. This error will be trapped if the HALT interrupt has been enabled.
  1541.  
  1542. ERROR: 3 SEVERITY: 20 MESSAGE: INSUFFICIENT MEMORY
  1543. The interpreter was unable to allocate enough memory for an operation. Since
  1544. memory space is required for all parsing and execution operations,this error
  1545. cannot usually be trapped by the SYNTAX interrupt.
  1546.  
  1547. ERROR: 4 SEVERITY: 10 MESSAGE: INVALID CHARACTER
  1548. A non-ASCII character was found in the program. Control codes and other non-
  1549. ASCII characters may be used in a program by defining them as hex or binary
  1550. strings. This is a scan phase error and cannot be trapped by the SYNTAX
  1551. interrupt.
  1552.  
  1553. ERROR: 5 SEVERITY: 10 MESSAGE: UNMATCHED QUOTE
  1554. A closing single or double quote was missing. Check that each string is
  1555. properly delimited. This is a scan phase error and cannot be trapped by the
  1556. SYNTAX interrupt.
  1557.  
  1558.                 103
  1559.  
  1560. ERROR: 6 SEVERITY: 10 MESSAGE: UNTERMINATED COMMENT
  1561. The closing "*/" for a comment field was not found. Remember that comments may
  1562. be nested,so each "/*" must be matched by a "*/." This is a scan phase error
  1563. and cannot be trapped by the SYNTAX interrupt.
  1564.  
  1565. ERROR: 7 SEVERITY: 10 MESSAGE: CLAUSE TOO LONG
  1566. A clause was too long for the internal buffer used as temporary storage. The
  1567. source line in question should be broken into smaller parts. This is a scan
  1568. phase error and cannot be trapped by the SYNTAX interrupt.
  1569.  
  1570. ERROR: 8 SEVERITY: 10 MESSAGE: INVALID TOKEN
  1571. An unrecognized lexical token was found,or a clause could not be properly
  1572. classified. This is a scan phase error and cannot be trapped by the SYNTAX
  1573. interrupt.
  1574.  
  1575. ERROR: 9 SEVERITY: 10 MESSAGE: SYMBOL OR STRING TOO LONG
  1576. An attempt was made to create a string longer than the maximum supported by the
  1577. interpreter. The implementation limits for internal structure are given in
  1578. Appendix B.
  1579.  
  1580. ERROR: 10 SEVERITY: 10 MESSAGE: INVALID MESSAGE PACKET
  1581. An invalid action code was found in a message packet sent to the ARexx resident
  1582. process. The packet was returned without being processed. This error is
  1583. detected by the external interface and cannot be trapped by the SYNTAX
  1584. interrupt.
  1585.  
  1586. ERROR: 11 SEVERITY: 10 MESSAGE: COMMAND STRING ERROR
  1587. A command string could not be processed. This error is detected by the external
  1588. interface and cannot be trapped by the SYNTAX interrupt.
  1589.  
  1590. ERROR: 12 SEVERITY: 10 MESSAGE: ERROR RETURN FROM FUNCTION
  1591. An external function returned a non-zero error code. Check that the correct
  1592. parameters were supplied to the function.
  1593.  
  1594. ERROR: 13 SEVERITY: 10 MESSAGE: HOST ENVIRONMENT NOT FOUND
  1595. The message port corresponding to a host address string could not be found.
  1596. Check that the required external host is active.
  1597.  
  1598. ERROR: 14 SEVERITY: 10 MESSAGE: REQUESTED LIBRARY NOT FOUND
  1599. An attempt was made to open a function library included in the Library List,but
  1600. the library could not be opened. Check that the correct name and version of the
  1601. library were specified when the library was added to the resource list.
  1602.  
  1603. ERROR: 15 SEVERITY: 10 MESSGE: FUNCTION NOT FOUND
  1604. A function was called that could not be found in any of the currently
  1605. accessible libraries,and could not be located as an external program. Check
  1606. that the appropriate function libraries have been added to the Libraries List.
  1607.  
  1608.                 104
  1609.  
  1610. ERROR: 16 SEVERITY: 10 MESSAGE: FUNCTION DID NOT RETURN VALUE
  1611. A function was called which failed to return a result string,but did not
  1612. otherwise report an error. Check that the function was programmed correctly,or
  1613. invoke it using the CALL instruction.
  1614.  
  1615. ERROR: 17 SEVERITY: 10 MESSAGE: WRONG NUMBER OF ARGUMENTS
  1616. A call was made to a function which expected more(or fewer)arguments. This
  1617. error will be generated if a Built-In or external function is called with more
  1618. arguments than can be accomodated in the message packet used for external
  1619. communications.
  1620.  
  1621. ERROR: 18 SEVERITY: 10 MESSAGE: INVALID ARGUMENT TO FUNCTION
  1622. An inappropriate argument was supplied to a function,or a required argument was
  1623. missing. Check the parameter requirements specified for the function.
  1624.  
  1625. ERROR: 19 SEVERITY: 10 MESSAGE: INVALID PROCEDURE
  1626. A PROCEDURE instruction was issued in an invalid context. Either no internal
  1627. functions were active,or a PROCEDURE had already been issued in the current
  1628. storage environment.
  1629.  
  1630. ERROR: 20 SEVERITY: 10 MESSAGE: UNEXPECTED THEN OR WHEN
  1631. A WHEN or THEN instruction was executed outside of a valid context. The WHEN
  1632. instruction is valid only within a SELECT range,and THEN must be the next
  1633. instruciton following an IF or WHEN.
  1634.  
  1635. ERROR: 21 SEVERITY: 10 MESSAGE: UNEXPECTED ELSE OR OTHERWISE
  1636. An ELSE or OTHERWISE was found outside of a valid context. The OTHERWISE
  1637. instruction is valid only within a SELECT range. ELSE is valid only following
  1638. the THEN branch of an IF range.
  1639.  
  1640. ERROR: 22 SEVERITY: 10 MESSAGE: UNEXPECTED BREAK,LEAVE,or ITERATE
  1641. The BREAK instruction is valid only within a DO range or inside an INTERPRETed
  1642. string. The LEAVE and ITERATE instuctions are valid only within an iterative DO
  1643. range.
  1644.  
  1645. ERROR: 23 SEVERITY: 10 MESSAGE: INVALID STATEMENT IN SELECT
  1646. A invalid statement was encountered within a SELECT range. Only WHEN,THEN,and
  1647. OTHERWISE statements are valid within a SELECT range,except for the conditional
  1648. statements following THEN or OTHERWISE clauses.
  1649.  
  1650. ERROR: 24 SEVERITY: 10 MESSAGE: MISSING OR MULTIPLE THEN
  1651. An expected THEN clause was not found,or another THEN was found after one had
  1652. already been executed.
  1653.  
  1654. ERROR: 25 SEVERITY: 10 MESSAGE: MISSING OTHERWISE
  1655. None of the WHEN clauses in a SELECT succeeded,but no OTHERWISE clause was
  1656. supplied.
  1657.  
  1658. ERROR: 26 SEVERITY: 10 MESSAGE: MISSING OR UNEXPECTED END
  1659. The program source ended before an END was found for a DO or SELECT instruction
  1660. or an END was encountered outside of a DO or SELECT range.
  1661.  
  1662.                 105
  1663.  
  1664. ERROR: 27 SEVERITY: 10 MESSAGE: SYMBOL MISMATCH
  1665. The symbol specified on an END,ITERATE,or LEAVE instruction did not match the
  1666. index variable for the associated DO range. Check that the active loops have
  1667. been nested properly.
  1668.  
  1669. ERROR: 28 SEVERITY: 10 MESSAGE: INVALID DO SYNTAX
  1670. An invalid DO instruction was executed. An initializer expression must be given
  1671. if a TO or BY expression is specified,and a FOR expression must yield a non-
  1672. negative integer result.
  1673.  
  1674. ERROR: 29 SEVERITY: 10 MESSAGE: INCOMPLETE IF OR SELECT
  1675. An IF or SELECT range ended before all of the required statement were found.
  1676. Check whether the conditional statement following a THEN,ELSE,or OTHERWISE
  1677. clause was omitted.
  1678.  
  1679. ERROR: 30 SEVERITY: 10 MESSAGE: LABEL NOT FOUND
  1680. A label specified by a SIGNAL instruction,or implicitly referenced by an
  1681. enabled interrupt,could not be found in the program source. Labels defined
  1682. dynamically by an INTERPRET instruction or by interactive input are not
  1683. included in the search.
  1684.  
  1685. ERROR: 31 SEVERITY: 10 MESSAGE: SYMBOL EXPECTED
  1686. A non-symbol token was found where only a symbol token is valid. The DROP,END,
  1687. LEAVE,ITERATE,and UPPER instructions may only be followed by a symbol token,and
  1688. will generate this error if anything else is supplied. This message will also
  1689. be issued if a required symbol is missing.
  1690.  
  1691. ERROR: 32 SEVERITY: 10 MESSAGE: SYMBOL OR STRING EXPECTED
  1692. An invalid token was found in a context where only a symbol or string is valid.
  1693.  
  1694. ERROR: 33 SEVERITY: 10 MESSAGE: INVALID KEYWORD
  1695. A symbol token in an instruction clause was identified as a keyword,but was
  1696. invalid in the specific context.
  1697.  
  1698. ERROR: 34 SEVERITY: 10 MESSAGE: REQUIRED KEYWORD MISSING
  1699. An instuction clause required a specific keyword token to be present,but it was
  1700. not supplied. For example,this messge will be issued if a SIGNAL ON instruction
  1701. is not followed by one of the interrupt keywords(e.g.SYNTAX.)
  1702.  
  1703. ERROR: 35 SEVERITY: 10 MESSAGE: EXTRANEOUS CHARACTERS
  1704. A seemingly valid statement was executed,but extra characters were found at the
  1705. end of the clause.
  1706.  
  1707. ERROR: 36 SEVERITY: 10 MESSAGE: KEYWORD CONFLICT
  1708. Two mutually exclusive keywords were included in an instruction clause,or a
  1709. keyword was included twice in the same instruction.
  1710.  
  1711. ERROR: 37 SEVERITY: 10 MESSAGE INVALID TEMPLATE
  1712. The template provided with an ARG,PARSE,or PULL instruction was not properly
  1713. constructed. Refer to Chapter 8 for a description of template structure and
  1714. processing.
  1715.  
  1716.                 106
  1717.  
  1718. ERROR: 38 SEVERITY: 10 MESSAGE: INVALID TRACE REQUEST
  1719. The alphabetic keyword supplied with a TRACE instruction or as the argument to
  1720. the TRACE()Built-In function was not valid. Refer to Chapter 7 for the valid
  1721. TRACE options.
  1722.  
  1723. ERROR: 39 SEVERITY: 10 MESSAGE: UNINITIALIZED VARIABLE
  1724. An attempt was made to use an uninitialized variable while the NOVALUE
  1725. interrupt was enabled.
  1726.  
  1727. ERROR: 40 SEVERITY: 10 MESSAGE: INVALID VARIABLE NAME
  1728. An attempt was made to assign a value to a fixed symbol.
  1729.  
  1730. ERROR: 41 SEVERITY: 10 MESSAGE: INVALID EXPRESSION
  1731. An error was detected during the evaluation an expression. Check that each
  1732. operator has the correct number of operands,and that no extraneous tokens
  1733. appear in the expression. This error will be detected only in expressions that
  1734. are actually evaluated. No checking is performed on expressions in clauses that
  1735. are being skipped.
  1736.  
  1737. ERROR: 42 SEVERITY: 10 MESSAGE: UNBALANCED PARENTHESE
  1738. An expression was found with an unequal number of opening and closing
  1739. parentheses.
  1740.  
  1741. ERROR: 43 SEVERITY: 43 MESSAGE: NESTING LIMIT EXCEEDED
  1742. The number of subexpressions in an expression was greater than the maximum
  1743. allowed. The expression should be simplified by breaking it into two or more
  1744. intermediate expressions.
  1745.  
  1746. ERROR: 44 SEVERITY: 10 MESSAGE: INVALID EXPRESSION RESULT
  1747. The result of an expression was not valid within its context. For example,this
  1748. messge will be issued if an increment or limit expression in a DO instruction
  1749. yields a non-numeric result.
  1750.  
  1751. ERROR: 45 SEVERITY: 10 MESSAGE: EXPRESSION REQUIRED 
  1752. An expression was omitted in a context where one is required. For example,the
  1753. SIGNAL instruction,if not followed by the keywords ON or OFF,must be followed
  1754. by an expression.
  1755.  
  1756. ERROR: 46 SEVERITY: 10 MESSAGE: BOOLEAN VALUE NOT 0 OR 1
  1757. An expression result was expected to yield a boolean result,but evaluated to
  1758. something other than 0 or 1.
  1759.  
  1760. ERROR: 47 SEVERITY: 10 MESSAGE: ARITHMETIC CONVERSION ERROR
  1761. A non-numeric operand was used in a operation requiring numeric operands. This
  1762. message will also be generated by an invalid hex or binary string.
  1763.  
  1764. ERROR: 48 SEVERITY: 10 MESSAGE: INVALID OPERAND
  1765. An operand was not valid for the intended operation. This message will be
  1766. generated if an attempt is made to divide by 0,or if a fractional exponent is
  1767. used in an exponentiation operation.
  1768.  
  1769.                 107
  1770.  
  1771.             APPENDIX B LIMITS AND COMPATIBILITY
  1772.  
  1773. ARexx was designed to adhere closely to the REXX language standard. This
  1774. appendix discusses those areas where ARexx departs from the standard.
  1775.  
  1776. B-1 LIMITS
  1777.  
  1778. Language definitions seldom include predefined limits to the program structures
  1779. that can be created. Only a few such restrictions were imposed in implementing
  1780. ARexx,and most of the internal structure are limited only by the total amount
  1781. of memory available. The current implementation limits are listed below.
  1782.  
  1783. LENGTH OF STRINGS. Strings,symbol names,and value strings are limited to a
  1784. maximum length of 65,535 bytes.
  1785.  
  1786. LENGTH OF CLAUSES. Clauses are limited to a maximum of 800 characters after
  1787. removing comments and multiple blanks.
  1788.  
  1789. NODES IN COMPOUND NAMES. Compound symbol names may include a maximum of 50
  1790. nodes,including the stem.
  1791.  
  1792. ARGUMENTS TO FUNCTIONS. Built-In and external functions are limited to a
  1793. maximum of 15 arguments. There is no limit to the number of arguments that may
  1794. be passed to an internal function.
  1795.  
  1796. SUBEXPRESSION NESTING. The maximum nesting level for subexpressions is 32.
  1797.  
  1798. B-2 COMPATIBILITY
  1799.  
  1800. ARexx departs in a few ways from the language definition. The differences can
  1801. be classified as omissions or extensions,and are described below.
  1802.  
  1803. OMISSIONS. The only significant specification of the language standard omitted
  1804. from this implementation is the arbitrary-precision arithmetic facility.
  1805. Arithmetic operations are limited to about 14 digits of precision,and the FUZZ
  1806. option is not implemented at all. Only the SCIENTIFIC format is used for
  1807. exponential notation. The full numeric capabilities will be provided in a later
  1808. release.
  1809.  
  1810. EXTENSIONS. The following extensions to the language standard have been
  1811. included in this implementation:
  1812.  
  1813. BREAK INSTRUCTION. A new instruction called BREAK has been implemented. It is
  1814. used to exit from the scope of any DO or INTERPRET instruction.
  1815.  
  1816. ECHO INSTRUCTION. The ECHO instruction has been included as a synonym for SAY.
  1817.  
  1818. SHELL INSTRUCTION. The SHELL instructiion has been included as a synonym for
  1819. ADDRESS.
  1820.  
  1821.                 109
  1822.  
  1823. SIGNAL OPTIONS. Several additional SIGNAL keywords have been implemented.
  1824. BREAK_C,BREAK_D,BREAK_E,and BREAK_F will detect and trap the control-C through
  1825. control-F signals passed by AmigaDOS. The IOERR keyword traps errors detected
  1826. by the I/O system.
  1827.  
  1828. STEM SYMBOLS. A stem symbol is valid anywhere that a simple symbol could be
  1829. employed.
  1830.  
  1831. TEMPLATE PROCESSING. Templates have been generalized in several ways. Variable
  1832. symbols may be used as positional tokens if preceded by an operator;the "="
  1833. operator is used to denote an absolute position. Multiple templates can be used
  1834. with all source forms of the PARSE instruction.
  1835.  
  1836.                 110
  1837.  
  1838.             APPENDIX C THE AREXX SYSTEMS LIBRARY
  1839.  
  1840. The ARexx interpreter is supplied as a shared library named rexxsyslib.library
  1841. and should reside in the system LIBS:directory. While many of the library
  1842. routines are highly specific to the interpreter,some of the functions will be
  1843. useful to applications that use ARexx. The library is opened when the ARexx
  1844. resident process is first loaded and will always be available while it remains
  1845. active.
  1846.  
  1847. The system library routines were designed to be called from assembly-language
  1848. programs and,unless otherwise noted,save all registers except for A0/A1 and
  1849. D0/D1. Many routines return values in more than one register to help reduce
  1850. code size. In addition,the routines will set the condition-code register(CCR)
  1851. wherever appropriate. In mode cases the CCR reflects the value returned in D0.
  1852.  
  1853. The library offsets are defined in the file rxslib.i,which should be INDLUDEd
  1854. in the program source code. Calls may be made from "C" programs if suitable
  1855. binding routines are provided when the program is linked. The definitions for
  1856. the constants and data structures used in ARexx are provided as INCLUDE files
  1857. on the program distribution disk. These should be reviewed carefully before
  1858. attempting to use the library functions.
  1859.  
  1860. C-1 FUNCTION GROUPS
  1861. The library functions can be frouped into Conversion,Input/Output,Resource
  1862. Management,and String Manipulation functions.
  1863.  
  1864. DATA CONVERSION. These functions provide many of the common data-conversion
  1865. requirements.
  1866.  
  1867. INPUT/0UTPUT. Two levels of I/O support are provided. The low level functions
  1868. use DOS filehandles directly,while the higher-level functions use linked lists
  1869. of IoBuff structures and support logical file names.
  1870.  
  1871. RESOURCE. These functions allocate,release,or otherwise manage the data
  1872. structures used with ARexx.
  1873.  
  1874. STRING FUNCTIONS. All data in ARexx are managed as strings. These functions
  1875. provide some of the more common string-manipulation operations.
  1876.  
  1877.                 111
  1878.  
  1879.             TABLE C.1 AREXX SYSTEMS LIBRARY FUNCTIONS
  1880.  
  1881. NAME        FUNCTIONAL GROUP    DESCRIPTION
  1882. AddClipNode    Resource        Allocate a Clip node
  1883. ClearMem    Resource        Clear a block of memory
  1884. ClearRexxMsg    Resource        Release argstrings from message
  1885. CloseF        Input/Output        Close a file buffer
  1886. ClosePublicPort    Resource        Close a port resource node
  1887. CmpString    String            Compare string structures for equality
  1888. CreateArgstring    Resource        Create an argstring structure
  1889. CreateDOSPkt    Input/Output        Creata a DOS Standard Packet
  1890. CreateRexxMsg    Resource        Create a message packet
  1891. CurrentEnv    Resource        Get current storage environment
  1892. CVa2i        Conversion        ASCII to integer
  1893. CVc2x        Conversion        Character to Hex or Binary digits
  1894. CVi2a        Conversion        Integer to ASCII
  1895. CVi2arg        Conversion        Integer to ASCII argstring
  1896. CVi2az        Conversion        Integer to ASCII,leading zeroes
  1897. CVs2i        Conversion        String structure to integer
  1898. CVx2c        Conversion        Hex or binary digits to binary
  1899. DeleteArgstring    Resource        Release an argstring structure
  1900. DeleteDOSPkt    Input/Output        Release a DOS Standard Packet
  1901. DeleteRexxMsg    Resource        Release a message packet
  1902. DOSRead        Input/Output        Read from a DOS filehandle
  1903. DOSWrite    Input/Output        Write to a DOS filehandle
  1904. ErrorMsg    Conversion        Get error message from error code
  1905. ExistF        Input/Output        Check whether a DOS file exists
  1906. FillRexxMsg    Resource        Convert and install argstrings
  1907. FindDevice    Input/Output        Locate a DOS device node
  1908. FindRsrcNode    Resource        Locate a resource node
  1909. FreePort    Resource        Close a message port
  1910. FreeSpace    Resource        Release internal memory
  1911. GetSpace    Resource        Allocate internal memory
  1912. InitList    Resource        Initialize a list header
  1913. InitPort    Resource        Initialize a message port
  1914. IsRexxMsg    Resource        Test a message packet
  1915. LengthArgstring    Resource        Get length of argstring
  1916. ListNames    Resource        Copy node names to an argstring
  1917. OpenF        Input/Output        Open a file buffer
  1918. OpenPublicPort    Resource        Allocate and open a port resource node
  1919. QueueF        Input/Output        Queue a line in a file buffer
  1920. ReadF        Input/Output        Read from a file buffer
  1921. ReadStr        Input/Output        Read a string from a file buffer
  1922. RemClipNode    Resource        Release a Clip node
  1923. RemRsrcList    Resource        Release a resource list
  1924. RemRsrcNode    Resource        Release a resource node
  1925.  
  1926.                 112
  1927.  
  1928.             TABLE C.1 LIBRARY FUNCTIONS (cont)
  1929.  
  1930. NAME        FUNCTIONAL GROUP    DESCRIPTION
  1931. SeekF        Input/Output        Reposition a file buffer
  1932. StackF        Input/Output        Stack a line in a file buffer
  1933. StcToken    String            Break out a token
  1934. StrcmpN        String            Compare strings
  1935. StrcpyA        String            Copy a string,converting to ASCII
  1936. StrcpyN        String            Copy a string
  1937. StrCpyU        String            Copy a string,converting to uppercase
  1938. StrflipN    String            Reverse characters in a string
  1939. Strlen        String            Find length of a string
  1940. ToUpper        Conversion        ASCII to uppercase
  1941. WriteF        Input/Output        Write to a file buffer
  1942.  
  1943. C-2 LIBRARY FUNCTIONS
  1944. The following descriptions of the ARexx Systems Library functions are listed
  1945. alphabetically. The required arguments and register assignments are shown in
  1946. parentheses after the function name. Multiple returns are shown in parentheses
  1947. on the left-hand side of the call.
  1948.  
  1949. AddClipNode()-allocate and link a Clip node
  1950. Usage:node=AddClipNode(list,name,length,value)
  1951.     D0        A0   A1    D0     D1
  1952.     A0        
  1953.        (CCR)
  1954.  
  1955. Allocates and links a Clip node into the specified list. Clip nodes are
  1956. resource nodes containing a name and value string,and include an "auto-delete"
  1957. function for simple maintenance. The list argument must point to a properly-
  1958. initialized EXEC list header. The name argument points to a null-terminated
  1959. name string,the value argument is a pointer to a storage area,and the length
  1960. argument is its length in bytes. The returned value is a pointer to the
  1961. allocated node,or 0 if the allocation failed.
  1962.  
  1963. The RemClipNode()function is installed as the "auto-delete" function for each
  1964. node. Clip nodes can be intermixed with other resource nodes in a list and then
  1965. released with a single call to RemRsrcList().
  1966. See Also:RemClipNode(),RemRsrcList(),RemRsrcNode()
  1967.  
  1968. AddRsrcNode()-allocate and link a resource node
  1969. Usage:node=AddRsrcNode(list,name,length)
  1970.     D0        A0   A1    D0
  1971.     A0
  1972.        (CCR)
  1973.  
  1974. Allocates and links a resource node(a RexxRsrc structure)to the specified list.
  1975. The name argument is a pointer to a null-terminated string,a copy of which is
  1976. installed in the node structure. The length argument is the total length for
  1977. the node;this length is saved within the node so that it may be released later.
  1978.  
  1979.                 113
  1980.  
  1981. The returned value is a pointer to the allocated node,or 0 if the allocation
  1982. failed.
  1983. See Also:RemRsrcList(),RemRsrcNode()
  1984.  
  1985. ClearMem()-clear a block of memory
  1986. Usage:ClearMem(address,length)
  1987.         A0       D0
  1988.  
  1989. Clears a block of memory beginning at the given address for the specified
  1990. length in bytes. The address must be word-aligned and the length must be a
  1991. multiple of 4 bytes;all structures allocated by ARexx meet these restrictions.
  1992. Register A0 is preserved.
  1993.  
  1994. ClearRexxMsg()-release argument strings
  1995. Usage:ClearRexxMsg(msgptr,count)
  1996.             A0     D0
  1997.  
  1998. Releases one or more argstrings from a message packet and clears the
  1999. corresponding slots. The count argument specifies the number of argument slots
  2000. to clear,and can be set to less than 16 to reserve some to the slots for
  2001. private use. No action is taken if the slot already contains a zero value.
  2002. See Also:FillRexxMsg()
  2003.  
  2004. CloseF()-close a file buffer
  2005. Usage:boolean=CloseF(IoBuff)
  2006.         D0             A0
  2007.  
  2008. Release the IoBuff structure and closes the associated DOS file. CloseF()is the
  2009. "auto-delete" function for the IoBuff structure,so an entire list of file
  2010. buffers can be closed with a single call to RemRsrcList().
  2011.  
  2012. ClosePublicPort()-close a port resource node 
  2013. Usage:ClosePublicPort(node)
  2014.                        A0
  2015.  
  2016. Unlinks and closes the message port and releases the resource node structure.
  2017. The node must have been allocated by the OpenPublicPort()function.
  2018. See Also:OpenPublicPort()
  2019.  
  2020. CmpString()-compare string structures for equality
  2021. Usage:test=CmpString(ss1,ss2)
  2022.        D0             A0 A1
  2023.       (CCR)
  2024.  
  2025. The arguments ss1 and ss2 must be pointers to ARexx string structures and are
  2026. compared for equality. String structures include the length and hash code of
  2027. the string,so the actual strings are not compared unless the lengths and hash
  2028. codes match. The return value sets the CCR and will be -1(True)if the strings
  2029. match and 0(False)otherwise.
  2030.  
  2031.                 114
  2032.  
  2033. CreateArgstring()-create an argument string structure
  2034. Usage:argstring=CreateArgstring(string,length)
  2035.           D0                      A0     D0
  2036.       A0
  2037.          (CCR)
  2038.  
  2039. Allocates a RexxArg structure and copies the supplied string into it. The
  2040. argstring return is a pointer to the string buffer of the structure,and can be
  2041. treated like an ordinary string pointer. The RexxArg structure stores the
  2042. structure size and string length at negative offsets to the string pointer. The
  2043. string pointer can be set to NULL if only an uninitialized structure is
  2044. required.
  2045. See Also:DeleteArgstring()
  2046.  
  2047. CreateDOSPkt()-allocate and initialize a DOS standard Packet.
  2048. Usage:packet = CreateDOSPkt()
  2049.        D0
  2050.        A0
  2051.       (CCR)
  2052.  
  2053. Allocates a DOS StandardPacket structure and initializes it by interlinking the
  2054. EXEC message and the DOS packet substructures. No replyport is installed in
  2055. either the message or the packet,as these fields are generally filled in just
  2056. before the message is sent.
  2057. See Also:DeleteDOSPkt()
  2058.  
  2059. CreateRexxMsg()-allocate an ARexx message packet
  2060. Usage: msgptr=CreateRexxMsg(replyport,extension,host)
  2061.          D0            A0       A1      D0
  2062.          A0
  2063.         (CCR)
  2064.  
  2065. This function allocates an ARexx message packet from the system free memory
  2066. list. The message packet consists of a standard EXEC message structure extended
  2067. to include space for function arguments,returned results,and internal defaults.
  2068. The replyport argument points to a public or private message port and must be
  2069. supplied,as it is required to return the message packet to the sender. The
  2070. extension and host arguments are pointers to null-terminated strings that
  2071. provide values for the default file extension and the initial host address,
  2072. respectively. Additional override fields in the extended packet except for the
  2073. primary and secondary result fields rm_Result1 and rm_Result2.
  2074. See Also: DeleteRexxMsg()
  2075.  
  2076. CVa2i()-convert from ASCII to integer
  2077. Usage: (digits,value) = CVa2i(buffer)
  2078.           D0     D1             A0
  2079.  
  2080. Converts the buffer of ASCII characters to a signed long integer value. The
  2081. scan proceeds until a non-digit character is found or until an overflow is
  2082. detected. The function returns both the number of digits scanned and the
  2083. converted value.
  2084.  
  2085.                 115
  2086.  
  2087. CVc2x()-convert(unpack)from character string to hex or binary digits.
  2088. Usage: error = CVc2x(outbuff,string,length,mode)
  2089.         D0             A0      A1     D0    D1
  2090.  
  2091. Converts the signed integer value argument to ASCII characters using the
  2092. supplied buffer pointer. The digits argument specifies the maximum number of
  2093. characters that will be copied to the buffer. The returned length is the actual
  2094. number of characters copied. The pointer return is the new buffer pointer.
  2095. See Also: CVi2az()
  2096.  
  2097. CVi2arg()-convert from integer to argstring
  2098. Usage: argstring=CVi2arg(value,digits)
  2099.           D0               D0    D1
  2100.       A0
  2101.      (CCR)
  2102.  
  2103. Converts the signed long integer value argument to ASCII characters,and
  2104. installs them in an argstring(a RexxArg structure). The returned value is an
  2105. argstring pointer or 0 if the allocation failed. The allocated structure can be
  2106. released using DeleteArgstring().
  2107.  
  2108. CVi2az()-convert from integer to ASCII with leading zeroes
  2109. Usage: (length,pointer)=CVi2az(buffer,value,digits)
  2110.           D0      A0            A0     D0    D1
  2111.  
  2112. Converts the signed long integer value argument to ASCII characters in the
  2113. supplied buffer,with leading zeroes to fill out the requested number of digits.
  2114. This function is identical to CVi2a except that leading zeroes are supplied.
  2115. See Also:CVi2a()
  2116.  
  2117. CVs2i()-convert from string structure to integer
  2118. Usage: (error,value)=CVs2i(ss)
  2119.          D0    D1          A0
  2120.  
  2121. The ss argument must be a pointer to a string structure. It is converted to a
  2122. signed long integer value return. The error return code is 47("Arithmetic
  2123. conversion error")if the string is not a valid number.
  2124.  
  2125.                 116
  2126.  
  2127. CVx2c()-convert from hex or binary digits to(packed)string
  2128. Usage:error=CVx2c(outbuff,string,length,mode)
  2129.        D0           A0      A1     D0    D1
  2130.  
  2131. Converts the string argument of hex(0-9,A-F)or binary(0,1)digits to the packed
  2132. binary representation. The mode argument specifies the(hex or binary)conversion
  2133. mode,and must be set to -1 for hex strings or 0 for binary strings. Blank
  2134. characters may be embedded in the string for readability,but only at byte
  2135. boundaries. The error return code is 47 if the string is not a valid hex or
  2136. binary string.
  2137.  
  2138. CurrentEnv()-return the current storage environment
  2139. Usage:envptr=CurrentEnv(rxtptr)
  2140.         D0                A0
  2141.  
  2142. Returns a pointer to the current storage environment associated with an
  2143. executing ARexx program. The rxptr argument is a pointer to the RexxTask
  2144. structure,and may be obtained from the message packet sent to an external
  2145. application.
  2146.  
  2147. DeleteArgstring()-delete(release)an argstring structure
  2148. Usage:DeleteArgstring(argstring)
  2149.                           A0
  2150.  
  2151. Releases an argstring (RexxArg) structure. The RexxArg structure contains the
  2152. total allocated length at a negative offset from the argstring pointer.
  2153. See Also:CreateArgstring()
  2154.  
  2155. DeleteDOSPkt()-release a DOS Standard Packet structure.
  2156. Usage:DeleteDOSPkt(message)
  2157.                       A0
  2158.  
  2159. Releases a DOS StandardPacket structure,typically obtained by a prior call to
  2160. CreateDOSPkt().
  2161. See Also:CreateDOSPkt()
  2162.  
  2163. DeleteRexxMsg()-delete(release)an ARexx message packet.
  2164. Usage:DeleteRexxMsg(packet)
  2165.                       A0
  2166.  
  2167. Release an ARexx message packet to the system free-memory list. The internal
  2168. MN-LENGTH field is used as the total size of the memory block to be released,so
  2169. this function can be used to release any message packet that contains the total
  2170. length in this field. Any embedded argument strings must be released before
  2171. calling DeleteRexxMsg().
  2172. See Also:CreateRexxMsg()
  2173.  
  2174.                 117
  2175.  
  2176. DOSREAD()-read from a DOS file
  2177. Usage:count=DOSRead(filehandle,buffer,length)
  2178.         D0              A0       A1     D0
  2179.        (CCR)
  2180.  
  2181. Reads one or more characters from a DOS filehandle into the supplied buffer.
  2182. The length argument specifies the maximum number of characters that will be
  2183. read. The returned count is the actual number of bytes transferred,or -1 if an
  2184. error occurred.
  2185.  
  2186. DOSWrite()-write to a DOS file
  2187. Usage:count=DOSWrite(filehandle,buffer,length)
  2188.        D0               A0        A1     D0
  2189.       (CCR)
  2190.  
  2191. Writes a buffer of the specified length to a DOS filehandle. The retuned count
  2192. is the actual number of bytes written,or -1 if an error occurred.
  2193.  
  2194. ErrorMsg()-find the message associated with an error code
  2195. Usage:(boolean,ss)=ErrorMsg(code)
  2196.           D0   A0            D0
  2197.  
  2198. Returns the error message(as a pointer to a string structure)associated with
  2199. the specified ARexx error code. The boolean return will be -1 if the supplied
  2200. code was a valid ARexx error code,and 0 otherwise.
  2201.  
  2202. ExistF()-check whether an external file exists
  2203. Usage:boolean=ExistF(filename)
  2204.         D0              A0
  2205.        (CCR)
  2206.  
  2207. Tests whether an external file currently exists by attempting to obtain a read
  2208. lock on the file. The boolean return indicates whether the operation succeeded,
  2209. and the lock is released.
  2210.  
  2211. FillRexxMsg()-convert and install arguments in message packet.
  2212. Usage:boolean=FillRexxMsg(msgptr,count,mask)
  2213.         D0                 A0     D0    D1
  2214.  
  2215. This function can be used to convert and install up to 16 argument strings in a
  2216. RexxMsg structure. The message packet must be allocated and the argument fields
  2217. of interest set to either a pointer to a null-terminated string or an integer
  2218. value. The count argument specifies the number of fields,beginning with ARGO,to
  2219. be converted into argstrings and installed into the argument slot. Bits 0-15 of
  2220. the mask argument specify whether the corresponding argument is a string
  2221. pointer(bit clear)or an integer value(bit set).
  2222.  
  2223.                 118
  2224.  
  2225. The count argument is normally set to the exact number of strings to be passed.
  2226. By setting this count to less than 16,a number of the slots can be reserved for
  2227. private uses.
  2228.  
  2229. The returned value is -1(True)if all of the arguments were successfully
  2230. converted. In the event of an allocation failure,all of the partial results are
  2231. released and a value of 0 is returned.
  2232. See Also:ClearRexxMsg()
  2233.  
  2234. FindDevice()-check whether a DOS device exists.
  2235. Usage:device=FindDevice(devicename,type)
  2236.         D0                  A0      D0
  2237.         A0
  2238.        (CCR)
  2239.  
  2240. Scans the DOS DeviceList for a device node of the specified type matching the
  2241. null-terminated name string. The acceptable values for the type argument are
  2242. the constants DLT_DEVICE,DLT_DIRECTORY,or DLT_VOLUME define in the DOS INCLUDE
  2243. files. Device names are conveted to uppercase before checking for a match. The
  2244. returned value is a pointer to the matched device node,or 0 if the device was
  2245. not found.
  2246.  
  2247. FindRsrcNode()-locate a resource node with the given name.
  2248. Usage:node=FindRsrcNode(list,name,type)
  2249.       D0                 A0   A1   D0
  2250.       A0
  2251.      (CCR)
  2252.  
  2253. Searchs the specified list for the first node of the selected type with the
  2254. given name. The list argument must be a pointer to a properly-initialized EXEC
  2255. list header. The name argument is a pointer to a null-terminated string. If the
  2256. type argument is 0,all nodes are selected;otherwise,the supplied type must
  2257. match the LN_TYPE field of the node. The returned value is a pointer to the
  2258. node or 0 if no matching node was found.
  2259.  
  2260. FreePort()-release resources associated with a message port
  2261. Usage:FreePort(port)
  2262.                 A0
  2263.  
  2264. This function deallocates the signal bit associated with a message port and
  2265. marks the port as "closed." The task calling FreePort()must be the same one
  2266. that initialized the port,since signal bit allocations are specific to a task.
  2267. The memory space associated with the port is not released.
  2268. See Also:InitPort()
  2269.  
  2270. FreeSpace()-releases space to the internal memory allocator.
  2271. Usage:FreeSpace(envptr,block,length)
  2272.                   A0     A1    D0
  2273.  
  2274. Returns a block of memory to the internal allocator,which must have been
  2275. obtained from a call to GetSpace(). The envptr argument is a pointer to the
  2276. base or current storage environment.
  2277. See Also:CurrentEnv(),GetSpace()
  2278.  
  2279.                 119
  2280.  
  2281. GetSpace()-allocate memory using the internal allocator.
  2282. Usage:block=GetSpace(envptr,length)
  2283.        D0              A0     D0
  2284.        A0
  2285.       (CCR)
  2286.  
  2287. Allocates a block of memory using the internal allocator. The memory is
  2288. obtained from an internal pool managed by the interpreter and is returned to
  2289. the operating system when the ARexx program terminates. The envptr argument is
  2290. a pointer to the base or current storage environment for the program.
  2291.  
  2292. The internal allocator must be used to allocate strings for use as values for
  2293. symbols,and is convenient for obtaining small blocks of memory whose lifetime
  2294. will not exceed that of the ARexx program.
  2295. See Also:CurrentEnv(),FreeSpace()
  2296.  
  2297. InitList()-initialize a list header
  2298. Usage:InitList(list)
  2299.                 A0
  2300.  
  2301. Initializes an EXEC list header structure.
  2302.  
  2303. InitPort()-initialize a previously-allocated message port.
  2304. Usage:(signal,port)=InitPort(port,name)
  2305.          D0    A1             A0   A1
  2306.  
  2307. Initializes a message port structure for which memory space has been previously
  2308. allocated,typically as part of a larger structure or as static storage in a
  2309. program. It installs the task ID(of the task calling the function)into the
  2310. MP_SIGTASK field and allocates a signal bit. The name parameter must be a
  2311. pointer to a null-terminated string. The signal return is the signal bit that
  2312. was allocated for the port. In the event that a signal could not be assigned,a
  2313. value of -1 is returned.
  2314.  
  2315. Note that the port is not linked into the system Ports List. If the port is to
  2316. be made public,this can be done after the function returns. The port address is
  2317. returned in the correct register(A1)for a subsequent call to the EXEC function
  2318. AddPort().
  2319. See Also:FreePort()
  2320.  
  2321. IsRexxMsg()-check whether a message came from ARexx.
  2322. Usage:boolean=IsRexxMsg(msgptr)
  2323.          D0               A0
  2324.  
  2325. Tests whether the message packet specified by the msgptr argument came from an
  2326. ARexx program. ARexx marks its messages with a pointer to a static string
  2327. "REXX" in the LN_NAME field. The returned value is either -1(True)if the
  2328. message came from ARexx or 0(False)otherwise.
  2329.  
  2330.                 120
  2331.  
  2332. IsSymbol()-check whether a string is a valid symbol.
  2333. Usage:(code,length)=IsSymbol(string)
  2334.         D0    D1               A0
  2335.  
  2336. Scans the supplied string pointer for ARexx symbol characters. The code return
  2337. is the symbol type if a symbol was found,or 0 if the string did not start with
  2338. a symbol character. The length return is the total length of the symbol.
  2339.  
  2340. ListNames()-build a string of names from a list.
  2341. Usage:argstring=ListNames(list,separator)
  2342.          D0                A0   D0[0:7]
  2343.          A0
  2344.         (CCR)
  2345.  
  2346. Scans the specified list and copies the name strings into an argstring. The
  2347. list argument must be a pointer to an initialized EXEC list header. The
  2348. separator argument is the character,possibly a null,to be placed as a delimiter
  2349. between the node names.
  2350.  
  2351. The list is traversed inside a Forbid()exclusion and so may be used with shared
  2352. or system lists. The returned argstring can be released using DeleteArgstring()
  2353. after the names are no longer needed.
  2354. See Also:DeleteArgstring()
  2355.  
  2356. LockRexxBase()-lock a shared resource.
  2357. Usage:LockRexxBase(resource)
  2358.                       D0
  2359.  
  2360. Secures the specified resource in the ARexx Systems Library base for read
  2361. access. The resource argument is a manifest constant for the required resource,
  2362. or zero to lock the entire structure.
  2363.  
  2364. Note that write access to shared resources is normally mediated by the ARexx
  2365. resident process,which operates at an elevated priority to gain exclusive
  2366. access. Locking a resource should not be attempted from a process operating at
  2367. a priority higher than the resident process.
  2368. See Also:UnlockRexxBase()
  2369.  
  2370. OpenF()-open a file buffer
  2371. Usage:IoBuff=OpenF(list,filename,mode,logical)
  2372.         D0          A0    A1      D0     D1
  2373.         A0
  2374.        (CCR)
  2375.  
  2376. Attempts to open an external file in the specified mode,which should be one of
  2377. the constants RXIO_READ,RXIO_WRITE,or RXIO_APPEND defined in the ARexx INCLUDE
  2378. files. 
  2379.  
  2380.                 121
  2381.  
  2382. If successful,an IoBuff structure is allocated and linked into the specified
  2383. list. The list argument must be a pointer to a properly-initialized EXEC list
  2384. header.
  2385.  
  2386. The optional logical argument is the logical name for the file,and must be
  2387. either a pointer to a null-terminated string or zero(NULL)if a name is not
  2388. required.
  2389. See Also:CloseF()
  2390.  
  2391. OpenPublicPort()-open a public message port
  2392. Usage:node=OpenPublicPort(list,name)
  2393.        D0                  A0   A1
  2394.        A0
  2395.       (CCR)
  2396.  
  2397. Allocates a message port as an "auto-delete" resource node and links it into
  2398. the specified list. The list argument must point to a properly initialized EXEC
  2399. list header. The message port is initialized with the given name and linked
  2400. into the system Ports List.
  2401. See Also:ClosePublicPort()
  2402.  
  2403. QueueF()-queue a line to a file buffer.
  2404. Usage:count-=QueueF(IoBuff,buffer,length)
  2405.         D0            A0     A1     D0
  2406.  
  2407. Queues a buffer of characters in the stream associated with the IoBuff
  2408. structure. The stream must be managed by a DOS handler that supports the
  2409. ACTION_QUEUE packet.
  2410.  
  2411. Queued lines are placed in "first-in,first-out" order and are immediately
  2412. available to be read from the stream. The buffer argument is a pointer to a
  2413. string of characters,and the length specifies the number of characters to be
  2414. queued. The return value is the actual count of characters or -1 if an error
  2415. occurred.
  2416. See Also:StackF()
  2417.  
  2418. ReadF()-read characters from a file buffer
  2419. Usage:count=ReadF(IoBuff,buffer,length)
  2420.        D0           A0     A1     D0
  2421.       (CCR)
  2422.  
  2423. Reads one or more characters from the file specified by the IoBuff pointer. The
  2424. buffer argument is a pointer to a storage area,and the length argument
  2425. specifies the maximum number of characters to be read. The return value is the
  2426. actual number of characters read,or -1 if an error occurred.
  2427.  
  2428. ReadStr()-read a string from a file
  2429. Usage:(count,pointer)=ReadStr(IoBuff,buffer,length)
  2430.         D0     A1               A0     A1     D0
  2431.  
  2432. Reads characters from the file specified by the IoBuff pointer until a
  2433. "newline" character is found. The "newline" is not included in the returned
  2434. string. The return value is the actual number of characters read,or -1 if an
  2435. error occurred.
  2436.  
  2437.                 122
  2438.  
  2439. See Also:ReadF()
  2440.  
  2441. RemClipNode()-unlink and deallocate a list Clip node.
  2442. Usage:RemClipNode(node)
  2443.                    A0
  2444.  
  2445. Unlinks and releases the specified Clip node. The function is the "auto-delete"
  2446. function for Clip nodes,and will be called automatically by RemRsrcNode() or
  2447. RemRsrcList().
  2448. See Also:AddClipNode(),RemRsrcList(),RemRsrcNode()
  2449.  
  2450. RemRsrcList()-unlink and deallocate a list of resource nodes
  2451. Usage:RemRsrcList(list)
  2452.                    A0
  2453.  
  2454. Scans the supplied list and releases any nodes found. The list must consist of
  2455. resource nodes(RexxRsrc structures),which contain information to allow
  2456. automatic cleanup and deletion.
  2457. See Also:RemRsrcNode()
  2458.  
  2459. RemRsrcNode()-unlink and deallocate a resource node
  2460. Usage:RemRsrcNode(node)
  2461.                    A0
  2462.  
  2463. Unlinks and releases the specified resource node,including the name string if
  2464. one is present. If an "auto-delete" function has been specified in the node,it
  2465. is called to perform any required resource deallocation before the node is
  2466. released.
  2467. See Also:RemRsrcList()
  2468.  
  2469. SeekF()-seek to the specified position in a file.
  2470. Usage:position=SeekF(IoBuff,offset,anchor)
  2471.         D0             A0    D0      D1
  2472.  
  2473. Seeks to a new position in the file is specified by the IoBuff pointer. The
  2474. position is given by the offset argument,a byte offset relative to the supplied
  2475. anchor argument. The anchor may specify the beginning(-1),the current position
  2476. (0),or the end of the file(1). The return value is the new position relative to
  2477. the beginning of the file.
  2478.  
  2479. StackF()-stack a line to a file buffer.
  2480. Usage:count=StackF(IoBuff,buffer,length)
  2481.         D0           A0     A1     D0
  2482.  
  2483. Stacks a buffer of characters in the stream associated with the IoBuff
  2484. structure. The buffer argument is a pointer to a string of characters,and the
  2485. length specifies the number of characters to be stacked. The return value is
  2486. the actual count of characters to be stacked. The return value is the actual
  2487. count of characters or -1 if an error occurred.
  2488.             
  2489.                 123
  2490.  
  2491. Stacked lines are placed in "last-in,first-out" order and are immediately
  2492. available to be read from the stream. The stream must be managed by a DOS
  2493. handler that supports the ACTION_STACK packet.
  2494. See Also:QueueF()
  2495.  
  2496. StcToken()-break out the next token from a string
  2497. Usage:(quote,length,scan,token)=StcToken(string)
  2498.         D0     D1    A0   A1               A0
  2499.  
  2500. Scans a null-terminated string to select the next token delimited by "white
  2501. space,"and returns a pointer to the start of the token. The quote return will
  2502. be an ASCII single or double quote if the token was quoted and 0 otherwise;
  2503. white space characters are ignored within quoted strings. The length return is
  2504. the total length of the token,including any quote characters. The scan return
  2505. is advanced beyond the current token to prepare for the next call.
  2506.  
  2507. StrcpyA()-copy a string,converting to ASCII
  2508. Usage:hash=StrcpyA(destination,source,length)
  2509.        D0              A0        A1     D0
  2510.  
  2511. Copies the source string to the destination area,converting the characters to
  2512. ASCII by clearing the high-order bit of each byte. The length of the string
  2513. (which may include embedded nulls)is considered as a 2-byte usingned integer.
  2514. So the string is limited in length to 65,535 bytes. The hash return is the
  2515. internal hash byte for the copied string.
  2516. See Also:StrcpyN(),StrcpyU
  2517.  
  2518. StrcpyN()-copy a string
  2519. Usage:hash=StrcpyN(destination,source,length)
  2520.        D0              A0        A1     D0
  2521.  
  2522. Copies the source string to the destination area. The length of the string
  2523. (which may include embedded nulls)is considered as a 2-byte unsigned integer.
  2524. The hash return is the internal hash byte for the copied string.
  2525. See Also:StrcpyA(),StrcpyU
  2526.  
  2527. StrcpyU()-copy a string,converting to uppercase
  2528. Usage:hash=StrcpyU(destination,source,length)
  2529.        D0               A0       A1     D0
  2530.  
  2531. Copies the source string to the destination area,converting to uppercase
  2532. alphabetics. The length of the string(which may include embedded nulls)is
  2533. considered as a 2-byte unsigned integer. The has return is the internal hash
  2534. byte for the copied string.
  2535. See Also:StrcpyA(),StrcpyN
  2536.  
  2537.                 124
  2538.  
  2539. StrflipN()-reverse the characters in a string
  2540. Usage:StrflipN(string,length)
  2541.                  A0     D0
  2542.  
  2543. Reverses the sequence of characters in a string. The conversion is performed in
  2544. place.
  2545.  
  2546. Strlen()-find the length of a null-terminated string
  2547. Usage:length=Strlen(string)
  2548.         D0            A0
  2549.        (CCR)
  2550.  
  2551. Returns the number of characters in a null-terminated string. Register A0 is
  2552. preserved,and the CCR is set for the returned length.
  2553.  
  2554. StrcmpN()-compare the values of strings
  2555. Usage:test=StrcmpN(string1,string2,length)
  2556.        D0             A0      A1     D0
  2557.       (CCR)
  2558.  
  2559. The string1 and string2 arguments are compared for the specified number of
  2560. characters. The comparison proceeds character-by-character until a difference
  2561. is found or the maximum number of characters have been examined. The returned
  2562. value is -1 if the first string was less,1 if the first string was greater,and
  2563. 0 if the strings match exactly. The CCR register is set for the returned value.
  2564.  
  2565. ToUpper()-translate an ASCII character to uppercase
  2566. Usage:upper=ToUpper(character)
  2567.        D0               D0
  2568.  
  2569. Converts an ASCII character to uppercase. Only register D0 is affected.
  2570.  
  2571. UnlockRexxBase()-unlock a shared resource.
  2572. Usage:UnlockRexxBase(resource)
  2573.                         D0
  2574.  
  2575. Releases the specified resource,or all resources if the argument is zero. Every
  2576. call to LockRexxBase()should be followed eventually by a call to UnlockRexxBase
  2577. ()for the same resource.
  2578. See Also:LockRexxBaseF()
  2579.  
  2580. WriteF()-write characters to a file buffer
  2581. Usage:count=WriteF(IoBuff,buffer,length)
  2582.         D0          A0      A1     D0
  2583.        (CCR)
  2584.  
  2585. Writes a buffer of characters of the specified length to the file associated
  2586. with the IoBuff pointer. The buffer argument is a pointer to a storage area,
  2587.  
  2588.                 125
  2589.  
  2590. and the length argument specifies the number of characters to be written. The
  2591. returned value is the actual number of characters written or -1 if an error
  2592. occurred.
  2593. See Also:CloseF(),OpenF(),ReadF()
  2594.  
  2595.                 126
  2596.  
  2597.             APPENDIX D THE AREXX SUPPORT LIBRARY
  2598.  
  2599. The ARexx language system is distributed with an external function library that
  2600. provides a number of Amiga-specific functions. It is a standard Amiga shared
  2601. library named rexxsupport.library and should reside in the system
  2602. LIBS:directory. Unlike the Systems Library described in the previous
  2603. Appendix,the support library functions are callable from with ARexx programs.
  2604.  
  2605. The support library was designed to supplement the generic Built-In functions
  2606. with functions specific to the Amiga. This library will be expanded in future
  2607. releases,and users are encouraged to submit suggestions for additional
  2608. functions. 
  2609.  
  2610. The Support Library must be added to the global Library List before it can be
  2611. accessed by ARexx programs. This can be done using the Built-In function
  2612. ADDLIB() or by direct communication with the resident process. The library name
  2613. must be specified as rexxsupport.library,the query function offset is -30,and
  2614. the version number is 0. The search priority can be set to 0 or whatever value
  2615. is appropriate.
  2616.  
  2617. ALLOCMEM()
  2618. Usage:ALLOCMEM(length,[attribute])
  2619. Allocates a block of memory of the specified length from the system free-
  2620. memory pool and returns its address as a 4-byte string. The optional attribute
  2621. parameter must be a standard EXEC memory allocation flag,supplied as a 4-byte
  2622. string. The default attribute is for "PUBLIC" memory(not cleared).
  2623.  
  2624. This function should be used whenever memory is allocated for use by external
  2625. programs. It is the user's responsibility to release the memory space when it
  2626. is no longer needed.
  2627. See Also:FREEMEM()
  2628. Example:
  2629.     say c2x(allocmem(1000))    ==>00050000
  2630.  
  2631. CLOSEPORT()
  2632. Usage:CLOSEPORT(name)
  2633. Closes the message port specified by the name argument,which must have been
  2634. allocated by a call to OPENPORT()within the current ARexx program. Any messages
  2635. received but not yet REPLYed are automatically returned with the return code
  2636. set to 10.
  2637. See Also:OPENPORT()
  2638. Example:
  2639.     call closeport myport
  2640.  
  2641.                 127
  2642.  
  2643. FREEMEM()
  2644. Usage:FREEMEM(address,length)
  2645. Releases a block of memory of the given length to the system freelist. The
  2646. address parameter is a four-byte string,typically obtained by a prior call to
  2647. ALLOCMEM(). FREEMEM()cannot be used to release memory allocated using
  2648. GETSPACE(),the ARexx internal memory allocator. The returned value is a boolean
  2649. success flag.
  2650. See Also:ALLOCMEM()
  2651. Example:
  2652.     say freemem('00042000'x,32)    ==>1
  2653.  
  2654. GETARG()
  2655. Usage:GETARG(packet,[n])
  2656. Extracts a command,function name,or argument string from a message packet. The
  2657. packet argument must be a 4-byte address obtained from a prior call to
  2658. GETPKT(). The optional n argument specifies the slot containing the string to
  2659. be extracted,and must be less than or equal to the actual argument count for
  2660. the packet. Commands and functions names are always in slot 0;function packets
  2661. may have argument strings in slots 1-15.
  2662. Examples:
  2663.     command = getarg(packet)
  2664.     function= getarg(packet,0)    /* name string    */
  2665.     arg1    = getarg(packet,1)    /* 1st argumeent*/
  2666.  
  2667. GETPKT()
  2668. Usage:GETPKT(name)
  2669. Checks the message port specified by the name argument to see whether any
  2670. messages are available. The named message port must have been opened by a prior
  2671. call to OPENPORT() within the current ARexx program. The returned value is the
  2672. 4-byte address of the first message packet,or '0000 0000'x if no packets were
  2673. available.
  2674.  
  2675. The function returns immediately whether or not a packet is enqueued at the
  2676. message port. Programs should never be designed to "busy-loop" on a message
  2677. port. If there is no useful work to be done until the next message packet
  2678. arrives,the program should call WAITPKT()and allow other tasks to proceed.
  2679. See Also:WAITPKT()
  2680. Example:
  2681.     packet = getpkt('MyPort')
  2682.  
  2683. OPENPORT()
  2684. Usage:OPENPORT(name)
  2685. Creates a public message port with the given name. The returned value is the
  2686. 4-byte address of the Port Resource strcture or '0000 000'xif the port could
  2687. not be opened or initialized. An initialization failure will occur if another
  2688. port of the same name already exists,or if a signal bit couldn't be allocated.
  2689.  
  2690.                 128
  2691.  
  2692. The message port is allocated as a Port Resource node and is linked into the
  2693. program's global data structure. Ports are automatically closed when the
  2694. program exits,and any pending messages are returned to the sender.
  2695. See Also:CLOSEPORT()
  2696. Example:
  2697.     myport = openport("MyPort")
  2698.  
  2699. REPLY()
  2700. Usage:REPLY(packet,rc)
  2701. Returns a message packet to the sender,with the primary result field set to the
  2702. value given by the rc argument. The secondary result is cleared. The packet
  2703. argument must be supplied as a 4-byte address,and the rc argument must be a
  2704. whole number.
  2705. Example:
  2706.     call reply packet,10        /* error return*/
  2707.  
  2708. SHOWDIR()
  2709. Usage:SHOWDIR(directory,['All' | 'File' | 'Dir'])
  2710. Returns the contents of the specified directory as a string of names separated
  2711. by blanks. The second parameter is an option keyword that selects whether all
  2712. entries,only files,or only subdirectories will be included.
  2713. Example:
  2714.     say showdir("df1:c")        ==>rx ts te hi tco tcc
  2715.  
  2716. SHOWLIST()
  2717. Usage:SHOWLIST[{'D' | 'L' | 'P' | 'R' | 'W' },[name])
  2718. The first argument is an option keyword to select a system list;the options
  2719. currently supported are Devices,Libraries,Ports,Ready,and Waiting. If only the
  2720. first parameter is supplied,the function scans the selected list and returns
  2721. the node names in a string separated by blanks. If the name parameter is
  2722. supplied,the boolean return indicates whether the specified list contains a
  2723. node of that name. The name matching is case-sensitive.
  2724.  
  2725. The list is scanned with task switching forbidden so as to provide an accurate
  2726. snapshot of the list at that time.
  2727. Example:
  2728.     say showlist('P')        ==>REXX MyCon
  2729.     say showlist('P','REXX')    ==>1
  2730.  
  2731.                 129
  2732.  
  2733. STATEF()
  2734. Usage:STATEF(filename)
  2735. Returns a string containing information about an external file. The string is
  2736. formatted as   "{DIR | FILE} length blocks protection comment."
  2737. The length token gives the file length in bytes,and the block token specifies
  2738. the file length in blocks.
  2739. Example:
  2740.     say statef("libs:rexxsupport.library")
  2741.     /* would give "FILE 1880 4 RWED "    */
  2742.  
  2743. WAITPKT()
  2744. Usage:WAITPKT(name)
  2745. Waits for a message to be received at the specified(named)port,which must have
  2746. been opened by a call to OPENPORT() within the current ARexx program. The
  2747. returned boolean value indicates whether a message packet is available at the
  2748. port. Normally the returned value will be 1(True),since the function waits
  2749. until an event occurs at the message port.
  2750.  
  2751. The packet must then be removed by a call to GETPKT(),and should be returned
  2752. eventually using the REPLY()function. Any message packets received but not
  2753. returned when an ARexx program exits are automatically REPLYed with the return
  2754. code set to 10.
  2755. Example:
  2756.     call waitpkt 'MyPort'    /* wait awhile    */
  2757.  
  2758.                 130
  2759.  
  2760.             APPENDIX E DISTRIBUTION FILES
  2761.  
  2762. This appendix lists the directores of the standard ARexx distribution disk. The
  2763. contents of some of the directories may change from time to time,so your disk
  2764. may not show exactly the same files. Most notably,the :rexx directory will
  2765. expand as more program examples are included in it.
  2766.  
  2767. The second section of the Appendix lists the HEADER files that define the
  2768. constants and data structures used with ARexx. All of these files are available
  2769. in the :INCLUDE directory,but are listed here for convenience in studying the
  2770. structures.
  2771.  
  2772. E-1 DIRECTORIES
  2773.  
  2774. The files are listed below as they would be using the system dir command. For
  2775. example,"dir df1:c opt a" would list the contents of the :c directory on disk
  2776. drive 1.
  2777.  
  2778. THE :C DIRECTORY
  2779.  
  2780. This directory contains the command utilities used with ARexx. These files
  2781. should be copied to your system C: directory when you install the program.
  2782.  
  2783.         c(dir)            
  2784.         hi            loadlib
  2785.         rexxmast        rx
  2786.         rxc            rxset
  2787.         tcc            tco
  2788.         te            ts
  2789.  
  2790. THE :INCLUDE DIRECTORY
  2791.  
  2792. This directory has the INCLUDE and HEADER files used for assembly language and
  2793. "C" programming,respectively. These files contain the structure definitions
  2794. necessary to build an interface to ARexx.
  2795.  
  2796.         include(dir)
  2797.         errors.h        rexxio.h
  2798.         rxslib.h        storage.h
  2799.         errors.i        rexxio.i
  2800.         rxslib.i        storage.i
  2801.  
  2802.                 131
  2803.  
  2804. THE :LIBS DIRECTORY
  2805.  
  2806. These are the library files for the language interpreter and the Support
  2807. Library functions. Both files should be copied to your system LIBS:directory
  2808. when you install ARexx.
  2809.  
  2810.         libs(dir)
  2811.         rexxsupport.library    rexxsyslib.library
  2812.  
  2813. THE :REXX DIRECTORY
  2814.  
  2815. The :rexx directory contains example programs to illustrate various features of
  2816. the language. New files will be added from time to time,and users are welcome
  2817. to contribute files to be distributed in this way.
  2818.  
  2819.         rexx(dir)
  2820.         bigif.rexx        break.rexx
  2821.         builtin.rexx        calc.rexx
  2822.         cmdtest.rexx        fact.rexx
  2823.         factw.rexx        haltme.rexx
  2824.         hosttest.rexx        iftest.rexx
  2825.         marquis.rexx        nesttest.rexx
  2826.         paver.rexx        potpourii.rexx
  2827.         rslib.rexx        select.rexx
  2828.         sigtest.rexx        support.rexx
  2829.         test1.rexx        timer.rexx
  2830.  
  2831. THE :TOOLS DIRECTORY
  2832.  
  2833. These files are intended for software developers,and include examples of
  2834. interfacing to ARexx. The file rexxtest is of particular interest;it calls the
  2835. ARexx interpreter directly,and can be run under a debugger to aid with
  2836. developing new function libraries.
  2837.  
  2838.         tools(dir)
  2839.         hosttest        hosttest.asm
  2840.         loadlib.asm        rexxtest
  2841.         rexxtest.asm        rxoffsets.o
  2842.  
  2843. Miscellaneous Files
  2844.  
  2845.         .info            Install-ARexx
  2846.         README            Start-Aexx
  2847.  
  2848.                 132
  2849.  
  2850. E-2 LISTINGS OF HEADER FILES
  2851.  
  2852. This section of the chapter consists of listings of the header files contained
  2853. in the :include directory.
  2854.  
  2855. storage.h
  2856.  
  2857. This is the main header file and contains definitions for all of the important
  2858. data structures used by ARexx.
  2859.  
  2860. /*===rexx/storage.h=================================================
  2861. *
  2862. * Copyright (c) 1986,1987 by William S. Hawes (All Rights Reserved)
  2863. *
  2864. *==================================================================
  2865. * Header file to define ARexx data structures.
  2866. */
  2867.  
  2868. #ifndef REXX_STORAGE_H
  2869. #define REXX_STORAGE_H
  2870.  
  2871. #ifndef EXEC_TYPES_H
  2872. #include "exec/types.h"
  2873. #endif
  2874. #ifndef EXEC_NODES_H
  2875. #include "exec/nodes.h"
  2876. #endif
  2877. #ifndef EXEC_LISTS_H
  2878. #include "exec/lists.h"
  2879. #endif
  2880. #ifndef EXEC_PORTS_H
  2881. #include "exec/ports.h"
  2882. #endif
  2883. #ifndef EXEC_LIBRARIES_H
  2884. #include "exec/libraries.h"
  2885. #endif
  2886.  
  2887. /* The NexxStr structue is used to maintain the internal strings in REXX.
  2888.  * It includes the buffer area for the string and associated attributes.
  2889.  * This is actually a variable-length structure;it is allocated for a
  2890.  * specific length string,and the length is never modified thereafter
  2891.  * (since it's used for recycling).
  2892.  */
  2893.  
  2894.                 133
  2895.  
  2896. storage.h(cont.)
  2897.  
  2898. struct NexxStr{
  2899.     LONG    ns_Ivalue;    /* integer value        */
  2900.     UWORD    ns_Length;    /* length in bytes(excl null)    */
  2901.     UBYTE    ns_Flags;    /* attribute flags        */
  2902.     UBYTE    ns_Hash;    /* hash code            */
  2903.     BYTE    ns_Buff[8];    /* buffer area for strings    */
  2904.     };            /* size: 16 bytes (minimum)    */
  2905.  
  2906. #define NXADDLEN 9        /* offset plus null byte    */
  2907. #define IVALUE(nsPtr) (nsPtr->ns_Ivalue)
  2908.  
  2909. /* String attribute flag bit definitions            */
  2910. #define NSB_KEEP    0    /* permanent string?        */
  2911. #define NSB_STRING    1    /* string form valid?        */
  2912. #define NSB_NOTNUM    2    /* non-numeric?            */
  2913. #define NSB_NUMBER    3    /* a valid number?        */
  2914. #define NSB_BINARY    4    /* integer value saved?        */
  2915. #define NSB_FLOAT    5    /* floating point format?    */
  2916. #define NSB_EXT        6    /* an external string?        */
  2917. #define NSB_SOURCE    7    /* part of the program source?    */
  2918.  
  2919. /* The flag form of the string attributes            */
  2920. #define    NSF_KEEP    (1<< NSB_KEEP  )            */
  2921. #define NSF_STRING    (1<< NSB_STRING)
  2922. #define NSF_NOTNUM    (1<< NSB_NOTNUM)
  2923. #define NSF_NUMBER    (1<< NSB_NUMBER)
  2924. #define NSF_BINARY    (1<< NSB_BINARY)
  2925. #define NSF_FLOAT    (1<< NSB_FLOAT )
  2926. #define NSF_EXT        (1<< NSB_EXT   )
  2927. #define NSF_SOURCE    (1<< NSB_SOURCE)
  2928.  
  2929. * Combinations of flags
  2930. #define    NSF_INTNUM    (NSF_NUMBER | NSF_BINARY | NSF_STRING)
  2931. #define NSF_DPNUM    (NSF_NUMBER | NSF_FLOAT)
  2932. #define NSF_ALPHA    (NSF_NOTNUM | NSF_STRING)
  2933. #define NSF_OWNED    (NSF_SOURCE | NSF_EXT | NSF_KEEP
  2934. #define KEEPSTR        (NSF_STRING | NSF_SOURCE | NSF_NOTNUM)
  2935. #define KEEPNUM        (NSF_STRING | NSF_SOURCE | NSF_NUMBER | NSF_BINARY)
  2936.  
  2937.                 134
  2938.  
  2939. storage.h (cont.)
  2940.  
  2941. /* The RexxArg structure is identical to the NexxStr structure,but
  2942.  * is allocated from system memory rather than from internal storage.
  2943.  * This structure is used for passing arguments to external programs.
  2944.  * It is usually passed as an "argstring",a pointer to the string buffer.
  2945.  */
  2946.  
  2947. struct RexxArg {
  2948.     LONG    ra_Size;    /* total allocated length    */
  2949.     UWORD    ra_Length;    /* length of string        */
  2950.     UBYTE    ra_Flags;    /* attribute flags        */
  2951.     UBYTE    ra_Hash;    /* hash code            */
  2952.     BYTE    ra_Buff[8];    /* buffer area            */
  2953.     };            /* size: 16 bytes (minimum)    */
  2954.  
  2955. /* The RexxMsg structure is used for all communications with Rexx programs.
  2956.  * It is an EXEC message with a parameter block appended.
  2957.  */
  2958. struct RexxMsg{
  2959.     struct Message rm_Node;    /* EXEC message structure    */
  2960.     APTR    rm_TaskBlock;    /* pointer to global structure    */
  2961.     APTR    rm_LibBase;    /* library base            */
  2962.     LONG    rm_Action;    /* command (action) code    */
  2963.     LONG    rm_Result1;    /* primary result (return code)    */
  2964.     LONG    rm_Result2;    /* secondary result        */
  2965.     STRPTR     rm_Args[16];    /* argument block(ARGO-ARG15)    */
  2966.     struct MsgPort *rm_PassPort;  /* forwarding port    */
  2967.     STRPTR    rm_CommAddr;    /* host address (port name)    */
  2968.     STRPTR    rm_FileExt;    /* file extension        */
  2969.     LONG    rm_Stdin;    /* input stream(filehandle)    */
  2970.     LONG    rm_Stdout;    /* output steam(filehandle)    */
  2971.     LONG    rm_avail;    /* future expension        */
  2972.     };            /* size: 128 bytes        */
  2973. /* Field definitions
  2974. #define ARGO(rmp) (rmp->rm_Args[0] /* start of argblock        */
  2975. #define ARG1(rmp) (rmp->rm_Args[1] /* first argument        */
  2976. #define ARG2(rmp) (rmp->rm_Args[2] /* second argument        */
  2977.  
  2978. #define MAXRMARG 15        /* maximum arguments        */
  2979.  
  2980. /* Command (action) codes for message packets            */
  2981. #define RXCOMM    $01000000    /* a command-level invocation    */
  2982. #define    RXFUNC    $02000000    /* a function call        */
  2983. #define RXCLOSE $03000000    /* close the port        */
  2984. #define RXQUERY    $04000000    /* query for information    */
  2985. #define RXADDFH    $07000000    /* add a function host        */
  2986.  
  2987.                 135
  2988.  
  2989. storage.h (cont.)
  2990.  
  2991. #define    RXADDLIB $08000000    /* add a function library    */
  2992. #define RXREMLIB $09000000    /* remove a function library    */
  2993. #define RXADDCON $0A000000    /* add/update a ClipList string */
  2994. #define RXREMCON $0B000000    /* remove a ClipList string    */
  2995. #define RXTCOPN     $0C000000    /* open the trace console    */
  2996. #define RXTCCLS     $0D000000    /* close the trace console    */
  2997.  
  2998. /* Command modifier flag bits                    */
  2999. #define    RXFB_NOIO    16    /* suppress I/O inheritance?    */
  3000. #define    RXFB_RESULT    17    /* result string expected?    */
  3001. #define    RXFB_STRING    18    /* program is a "string file"?    */
  3002. #define    RXFB_TOKEN    19    /* tokenize the command line?    */
  3003. #define    RXFB_NONRET    20    /* a "no-return" message?    */
  3004.  
  3005. /* Modifier flags                        */
  3006. #define    RXFF_RESULT    (1<< RSFB_RESULT)
  3007. #define    RXFF_STRING    (1<< RXFB_STRING)
  3008. #define    RXFF_TOKEN    (1<< RXFB_TOKEN )
  3009. #define    RXFF_NONRET    (1<< RXFB_NONRET)
  3010. #define    RXCODEMASK    $FF000000
  3011. #define RXARGMASK    $0000000F
  3012.  
  3013. /* The RexxRsrc structure is used to manage global resources.
  3014.  * The name string for each node is created as a RexxArg structure,
  3015.  * and the total size of the node is saved in the "rr_Size" field.
  3016.  * Functions are provided to allocate and release resource nodes.
  3017.  * If special deletion operations are required,an offset and base can
  3018.  * be provided in "rr_Func" and "rr_Base",respectively. This function
  3019.  * will be called with the base in register A6 and the node in A0.
  3020. */
  3021. struct RexxRsrc {
  3022.     struct Node rr_Node;
  3023.     WORD    rr_Func;    /* a "auto-delete" offset    */
  3024.     APTR    rr_Base;    /* "auto-delete" base        */
  3025.     LONG    rr_Size;    /* total size of node        */
  3026.     LONG    rr_Arg1;    /* available ...        */
  3027.     LONG    rr_Arg2;    /* available ...        */
  3028.     };            /* size: 32 bytes        */
  3029. /* Resource node types                        */
  3030. #define    RRT_ANY        0    /* any node type ...        */
  3031. #define    RRT_LIB        1    /* a function library        */
  3032. #define    RRT_PORT    2    /* a public port        */
  3033. #define    RRT_FILE    3    /* a file IoBuff        */
  3034. #define    RRT_HOST    4    /* a function host        */
  3035. #define    RRT_CLIP    5    /* a Clip List node        */
  3036.  
  3037.                 136
  3038.  
  3039. storage.h (cont.)
  3040.  
  3041. /* The RexxTask structure holds the fields used by REXX to communicate with
  3042.  * external processes,including the client task. It includes the global
  3043.  * data structure(and the base environment). The structure is passed to
  3044.  * the newly-created task in its "wake-up" message.
  3045. */
  3046.  
  3047. #define GLOBALSZ    200    /* total size of GlobalData    */
  3048. struct RexxTask {        
  3049. BYTE    rt_Global[GLOBALSZ];     /* global data structure    */
  3050. struct MsgPort rt_MsgPort;    /* global message port        */
  3051. UBYTE    rt_Flags;        /* task flag bits        */
  3052. BYTE    rt_SigBit;        /* signal bit            */
  3053.  
  3054. APTR    rt_ClientID;        /* the client's task ID        
  3055. APTR    rt_MsgPkt;        /* the packet being processed
  3056. APTR    rt_TaskID;        /* our task ID
  3057. APTR    rt_RexxPort;        /* the REXX public port
  3058.  
  3059. APTR    rt_ErrTrap;        /* Error trap address
  3060. APTR    rt_StackPtr;        /* stack pointer for traps
  3061.  
  3062. struct List rt_Header1;        /* Environment list        */
  3063. struct List rt_Header2;        /* Memory freelist        */
  3064. struct List rt_Header3;        /* Memory allocation list    */
  3065. struct List rt_Header4;        /* Files list            */
  3066. struct List rt_Header5;        /* Message Ports List        */
  3067. };    
  3068.  
  3069. /* Definitions for RexxTask flag bits
  3070. #define    RTFB_TRACE    0    /* external trace flag        */
  3071. #define RTFB_HALT    1    /* external halt flag        */
  3072. #define    RTFB_SUSP    2    /* suspend task?        */
  3073. #define RTFB_TCUSE    3    /* trace console in use?    */
  3074. #define    RTFB_WAIT    6    /* waiting for reply?        */
  3075. #define RTFB_CLOSE    7    /* task completed?        */
  3076.  
  3077. /* Definitions for memory allocation constants            */
  3078. #define MEMQUANT    16        /* quantum of memory space    */
  3079. #define MEMMASK        $FFFFFFF0    /* mask for rounding the size    */
  3080.  
  3081. #define MEMQUICK    (1 << 0 )    /* EXEC flags: MEMF_PUBLIC    */
  3082. #define MEMCLEAR    (1 << 16)    /* EXEC flags: MEMF_CLEAR    */
  3083.  
  3084.                 137
  3085.  
  3086. storage.h (cont.)
  3087.  
  3088. /* The SrcNode is a temporary structure used to hold values destined for a
  3089.  * segment array. It is also used to maintain the memory freelist.
  3090. */
  3091.  
  3092. struct SrcNode {
  3093. struct SrcNode *sn_Succ;    /* next node            */
  3094. struct SrcNode *sn_Pred;
  3095. APTR    sn_Ptr;            /* pointer value        */
  3096. LONG    sn_Size;        /* size of object        */
  3097. };                /* size: 16 bytes        */
  3098. #endif
  3099.  
  3100.                 138
  3101.  
  3102. rxslip.h
  3103.  
  3104. This file defines the library base for the ARexx Systems Library.
  3105.  
  3106. /* === rexx/rxslib.h========================================================
  3107. *
  3108. * Copyright (c) 1986,1987 by William S. Hawes (All Rights Reserved)
  3109. *
  3110. *===========================================================================
  3111. * The header file for the REXX Systems Library
  3112. */
  3113.  
  3114. #ifndef REXX_RXSLIB_H
  3115. #define REXX_RXSLIB_H
  3116.  
  3117. #ifndef REXX_STORAGE_H
  3118. #include "rexx/storage.h"
  3119. #endif
  3120.  
  3121. /* Some macro definitions                    */
  3122.  
  3123. #define RXSNAME    "rexxsyslib.library"
  3124. #define    RXSID    "rexxsyslib 1.0 (23 AUG 87)"
  3125. #define RXSDIR    "REXX"
  3126. #define    RXSTNAME "ARexx"
  3127.  
  3128. /* The REXX systems library structure. This should be considered */
  3129. /* semi-private and read-only,except for documented exceptions     */
  3130.  
  3131. struct RxsLib {
  3132. struct Library rl_Node;        /* EXEC library node        */
  3133. UBYTE    rl_Flags;        /* global flags            */
  3134. UBYTE    rl_pad;
  3135. APTR    rl_SysBase;        /* EXEC library base        */
  3136. APTR    rl_DOSBase;        /* DOS library base        */
  3137. APTR    rl_IeeeDPBase;        /* IEEE DP match library base    */
  3138. LONG    rl_SegList;        /* library seglist        */
  3139. LONG    rl_MaxAlloc;        /* maximum expression allocation*/
  3140. LONG    rl_Chunk;        /* allocation quantum        */
  3141. LONG    rl_MaxNest;        /* maximum expression nesting    */
  3142. struct NexxStr *rl_NULL;    /* static string: NULL        */
  3143. struct NexxStr *rl_FALSE;    /* static string: FALSE        */
  3144. struct NexxStr *rl_TRUE;    /* static string: TRUE        */
  3145. struct NexxStr *rl_REXX;    /* static string: REXX        */
  3146. struct NexxStr *rl_COMMAND;    /* static string: COMMAND
  3147. struct NexxStr *rl_STDIN;    /* static string: STDIN
  3148. struct NexxStr *rl_STDOUT;    /* static string: STDOUT
  3149. struct NexxStr *rl_STDERR;    /* static string: STDERR
  3150.  
  3151.                 139
  3152.  
  3153. rxslib.h (cont.)
  3154.  
  3155. STRPTR    rl_Version;        /* version/configuration string */
  3156. STRPTR    rl_TaskName;        /* name string for tasks    */
  3157. LONG    rl_TaskPri;        /* starting prioity        */
  3158. LONG    rl_TaskSeg;        /* startup seglist        */
  3159. LONG    rl_StackSize;        /* stack size            */
  3160. STRPTR    rl_RexxDir;        /* REXX directory        */
  3161. STRPTR    rl_CTABLE;        /* character attribute table    */
  3162. struct NexxStr *rl_Notice;    /* copyright notice        */
  3163.  
  3164. struct MsgPort rl_RexxPort;    /* REXX public port        */
  3165. UWORD    rl_ReadLock;        /* lock count            */
  3166. LONG    rl_TraceFH;        /* global trace console        */
  3167. struct List rl_TaskList;    /* REXX task list        */
  3168. WORD    rl_NumTask;        /* task count            */
  3169. struct List rl_TaskList;    /* Library List header        */
  3170. WORD    rl_NumLib;        /* library count        */
  3171. struct List rl_ClipList;    /* ClipList header        */
  3172. WORD    rl_NumClip;        /* clip node count        */
  3173. struct List rl_MsgList;        /* pending messages        */
  3174. WORD    rl_NumMsg;        /* pending count        */
  3175. };
  3176.  
  3177. /* Global flag bit definitions for RexxMaster            */
  3178. #define RLFB_TRACE RTFB_TRACE    /* interactive tracing?        */
  3179. #define RLFB_HALT  RTFB_HALT    /* halt execution?        */
  3180. #define RLFB_SUSP  RTFB_SUSP    /* suspend execution?        */
  3181. #define RLFB_TCUSE RTFB_TCUSE    /* trace console in use?    */
  3182. #define RLFB_TCOPN 4        /* trace console open?        */
  3183. #define RLFB_STOP  6        /* deny further invocations    */
  3184. #define RLFB_CLOSE 7        /* close the master        */
  3185.  
  3186. #define RLFMASK       0x07        /* passed flags            */
  3187.  
  3188.     ; Initialization constants
  3189.  
  3190. #define RXSVERS      2        /* main version            */
  3191. #define RXSREV      1        /* revision            */
  3192. #define RXSALLOC  0x800000    /* maximum allocation        */
  3193. #define RXSCHUNK  1024        /* allocation quantum        */
  3194. #define RXSNEST   32        /* expression nesting limit    */
  3195. #define RXSTPRI      0        /* task priority        */
  3196. #define RXSSTACK  4096        /* stack size            */
  3197. #define RXSLISTH  4        /* number of list headers    */
  3198.  
  3199.                 140
  3200.  
  3201. rxslib.h (cont.)
  3202.  
  3203. /* Character attribute flag bits used in REXX. Defined only for    */
  3204. /* ASCII characters (range 0-127)                */
  3205.  
  3206. #define    CTB_SPACE    0    /* white space characters    */
  3207. #define    CTB_DIGIT    1    /* decimal digits 0-9        */
  3208. #define    CTB_ALPHA    2    /* alphabetic characters    */
  3209. #define    CTB_REXXSYM    3    /* REXX symbol characters    */
  3210. #define    CTB_REXXOPR    4    /* REXX operator characters    */
  3211. #define    CTB_REXXSPC    5    /* REXX special symbols        */
  3212. #define    CTB_UPPER    6    /* UPPERCASE alphabetic        */
  3213. #define    CTB_LOWER    7    /* lowercase alphabetic        */
  3214.  
  3215. /* Attribute flags                        */
  3216. #define    CTF_SPACE    (1 << CTB_SPACE)
  3217. #define CTF_DIGIT    (1 << CTB_DIGIT)
  3218. #define CTF_ALPHA    (1 << CTB_ALPHA)
  3219. #define CTF_REXXASYM    (1 << CTB_REXXSYM)
  3220. #define    CTF_REXXOPR    (1 << CTB_REXXOPR)
  3221. #define CTF_REXXSPC    (1 << CTB_REXXSPC)
  3222. #define CTF_UPPER    (1 << CTB_UPPER)
  3223. #define CTF_LOWER    (1 << CTB_LOWER)
  3224.  
  3225. #endif
  3226.  
  3227.                 141
  3228.  
  3229. rexxio.h
  3230.  
  3231. This file defines the data structures used for buffered I/O. ARexx uses linked
  3232. lists of IoBuff structures to keep track of the files it opens. Each IoBuff
  3233. node is allocated as an "auto-delete" structure and can be closed and released
  3234. by a call to either CloseF() or RemRsrcNode(). An entire list of files can be
  3235. closed with a call to RemRsrcList().
  3236.  
  3237. /* ===rexx/rexxio.h========================================================
  3238.  *
  3239.  * Copyright (c) 1986,1987 by William S. Hawes (All Rights Reserved)
  3240.  *
  3241.  *=========================================================================
  3242.  * Header file for ARexx Input/Output related structures
  3243. */
  3244.  
  3245. #ifndef REXX_REXXIO_H
  3246. #define REXX_REXXIO_H
  3247.  
  3248. #ifndef REXX_STORAGE_H
  3249. #include "rexx/storage.h"
  3250. #endif
  3251.  
  3252. #define RXBUFFSZ 204            /* buffeg length    */
  3253.  
  3254. /* The IoBuff is a resource node used to maintain the File List. Nodes are
  3255.  * allocated and linked into the list whenever a file is opened.
  3256. */
  3257.  
  3258. struct IoBuff{
  3259. struct RexxRsrc iobNode;        /* structure for files/strings     */
  3260. APTR    iobRpt;                /* read/write pointer        */
  3261. LONG    iobRct;                /* character count        */
  3262. LONG    iobDFH;                /* DOS filehandle        */
  3263. APTR    iobLock;            /* DOS lock            */
  3264. LONG    iobBct;                /* buffer length        */
  3265. BYTE    iobArea[RXBUFFSZ];        /* buffer area            */
  3266. };                    /* size: 256 bytes        */
  3267.  
  3268. /* Access mode definitions                        */
  3269. #define RXIO_EXIST -1            /* an external filehandle    */
  3270. #define RXIO_STRF 0            /* a "string file"        */
  3271. #define RXIO_READ 1            /* read-only access        */
  3272. #define RXIO_WRITE 2            /* write mode            */
  3273. #define RXIO_APPEND 3            /* append mode (existing file)    */
  3274.  
  3275.                 142
  3276.  
  3277. rxxio.h (cont.)
  3278.  
  3279. /* Offset anchors for SeekF()                        */
  3280. #define RXIO_BEGIN -1            /* relative to start        */
  3281. #define RXIO_CURR 0            /* relative to current position */
  3282. #define RXIO_END 1            /* relative to end        */
  3283.  
  3284. /* The Library List contains just plain resource nodes            */
  3285.  
  3286. #define LLOFFSET(rrp) (rrp>rr_Arg1)    /* "Query" offset        */
  3287. #define LLVERS(rrp)   (rrp->Arg2)    /* library version        */
  3288.  
  3289. /* The RexxClipNode structure is used to maintain the Clip List. The
  3290.  * The ReplyList holds packets that have been received but haven't been
  3291. * replied.
  3292. */
  3293.  
  3294. struct RexxMsgPort{
  3295. struct RexxRsrc rmp_Node;        /* linkage node            */
  3296. struct MsgPort rmp_Port;        /* the message port        */
  3297. struct List    rmp_ReplyList;        /* messages awaiting reply    */
  3298. };
  3299.  
  3300. /* DOS Device types                            */
  3301. #define DT_DEV    0            /* a device            */
  3302. #define DT_DIR      1            /* an ASSIGNed directory    */
  3303. #define DT_VOL      2            /* a volume            */
  3304.  
  3305. /* Private DOS packet types                        */
  3306. #define ACTION_STACK 2002        /* stack a line            */
  3307. #define ACTION_QUEUE 2003        /* queue a line            */
  3308. #endif
  3309.  
  3310.                 143
  3311.  
  3312. errors. h
  3313.  
  3314. This file contains the definitions for all of the error messages issued by the
  3315. ARexx interpreter.
  3316.  
  3317. /* == errors.h================================================================
  3318.  *
  3319.  * Copyright (c) 1987 by Williams S. Hawes (All Rights Reserved)
  3320.  *
  3321.  * ===========================================================================
  3322.  * Definitions for ARexx error codes
  3323. */
  3324.  
  3325. #define EERC_MSG 0            /* error code offset        */
  3326. #define ERR10_001 (ERRC_MSG+1)        /* program not found        */
  3327. #define ERR10_002 (ERRC_MSG+2)        /* execution halted        */
  3328. #define ERR10_003 (ERRC_MSG+3)        /* no memory available        */
  3329. #define ERR10_004 (ERRC_MSG+4)        /* invalid character in program */
  3330. #define ERR10_005 (ERRC_MSG+5)        /* unmatched quote        */
  3331. #define ERR10_006 (ERRC_MSG+6)        /* unterminated comment        */
  3332. #define ERR10_007 (ERRC_MSG+7)        /* clause too long        */
  3333. #define ERR10_008 (ERRC_MSG+8)        /* unrecognized token        */
  3334. #define ERR10_009 (ERRC_MSG+9)        /* symbol or string too long    */
  3335.  
  3336. #define ERR10_010 (ERRC_MSG+10)        /* invalid message packet    */
  3337. #define ERR10_011 (ERRC_MSG+11)        /* command string error        */
  3338. #define ERR10_012 (ERRC_MSG+12)        /* error return from function    */
  3339. #define ERR10_013 (ERRC_MSG+13)        /* host environment not found    */
  3340. #define ERR10_014 (ERRC_MSG+14)        /* required library not found    */
  3341. #define ERR10_015 (ERRC_MSG+15)        /* function not found        */
  3342. #define ERR10_016 (ERRC_MSG+16)        /* no return value        */
  3343. #define ERR10_017 (ERRC_MSG+17)        /* wrong number of arguments    */
  3344. #define ERR10_018 (ERRC_MSG+18)        /* invalid argument to function */
  3345. #define ERR10_019 (ERRC_MSG+19)        /* invalid PROCEDURE        */
  3346.  
  3347. #define ERR10_020 (ERRC_MSG+20)        /* unexpected THEN/ELSE        */
  3348. #define ERR10_021 (ERRC_MSG+21)        /* unexpected WHEN/OTHERWISE    */
  3349. #define ERR10_022 (ERRC_MSG+22)        /* unexpected LEAVE or ITERATE    */
  3350. #define ERR10_023 (ERRC_MSG+23)        /* invalid statement in SELECT    */
  3351. #define ERR10_024 (ERRC_MSG+24)        /* missing THEN clauses        */
  3352. #define ERR10_025 (ERRC_MSG+25)        /* missing OTHERWISE        */
  3353. #define ERR10_026 (ERRC_MSG+26)        /* missing or unexpected END    */
  3354. #define ERR10_027 (ERRC_MSG+27)        /* symbol mismatch on END    */
  3355. #define ERR10_028 (ERRC_MSG+28)        /* invalid DO syntax        */
  3356. #define ERR10_029 (ERRC_MSG+29)        /* incomplete DO/IF/SELECT    */
  3357.  
  3358.                 144
  3359.  
  3360. errors.h (cont.)
  3361.  
  3362. #define ERR10_030 (ERRC_MSG+30)        /* label not found        */
  3363. #define ERR10_031 (ERRC_MSG+31)        /* symbol expected        */
  3364. #define ERR10_032 (ERRC_MSG+32)        /* string or symbol expected    */
  3365. #define ERR10_033 (ERRC_MSG+33)        /* invalid sub-keyword        */
  3366. #define ERR10_034 (ERRC_MSG+34)        /* required keyword missing    */
  3367. #define ERR10_035 (ERRC_MSG+35)        /* extraneous characters    */
  3368. #define ERR10_036 (ERRC_MSG+36)        /* sub-keyword conflict        */
  3369. #define ERR10_037 (ERRC_MSG+37)        /* invalid template        */
  3370. #define ERR10_038 (ERRC_MSG+38)        /* invalid TRACE request    */
  3371. #define ERR10_039 (ERRC_MSG+39)        /* uninitialized variable    */
  3372.  
  3373. #define ERR10_040 (ERRC_MSG+40)        /* invalid variable name    */
  3374. #define ERR10_041 (ERRC_MSG+41)        /* invalid expression        */
  3375. #define ERR10_042 (ERRC_MSG+42)        /* unbalanced parentheses    */
  3376. #define ERR10_043 (ERRC_MSG+43)        /* nesting level exceeded    */
  3377. #define ERR10_044 (ERRC_MSG+44)        /* invalid expression result    */
  3378. #define ERR10_045 (ERRC_MSG+45)        /* expression required        */
  3379. #define ERR10_046 (ERRC_MSG+46)        /* boolean value not 0 or 1    */
  3380. #define ERR10_047 (ERRC_MSG+47)        /* arithmetic conversion error    */
  3381. #define ERR10_048 (ERRC_MSG+48)        /* invalid operand        */
  3382.  
  3383. /* Return Codes for general use ...                    */
  3384. #define RC_FAIL -1            /* something's wrong        */
  3385. #define RC_OK 0                /* success            */
  3386. #define RC_WARN 5            /* warning only            */
  3387. #define RC_ERROR 10            /* something's wrong        */
  3388. #define RC_FATAL 20            /* complete or severe failure    */
  3389.  
  3390.                 145
  3391.  
  3392.                   GLOSSARY
  3393.  
  3394. ALLOCATION. A grant of a system resource,such as memory space. Programs
  3395. designed to run in a multitasking environment generally use dynamic allocation
  3396. to avoid tying up system resources.
  3397.  
  3398. AMIGADOS. The higher-level part of the Amiga operating system that supports the
  3399. filing system and input/output operations.
  3400.  
  3401. ARGSTRING. An "argument string" structure used to pass data to an ARexx
  3402. program. The structure is passed as a pointer to the buffer area containing the
  3403. string data,and can be treated as a pointer to a null-terminated string.
  3404.  
  3405. ARGUMENT. A data item passed to a function,sometimes called a parameter.
  3406.  
  3407. CLAUSE. A group of one or more tokens forming a "sentence" in a language. The
  3408. clause is the smallest executable language fragment.
  3409.  
  3410. COMMAND LINE INTERFACE (CLI). A program that accepts input from the user and
  3411. runs programs based on the entered command. The CLI generally refers to the
  3412. command interpreter supplied with the Amiga,but other command "shells" may be
  3413. used instead.
  3414.  
  3415. CONCATENATION. An operation in which two strings are joined or "chained
  3416. together." ARexx provides two concatenation operators,one of which joins
  3417. strings directly and the other of which embeds a blank between the operands.
  3418.  
  3419. EXEC. The multitasking kernel of the Amiga's operating system. EXEC provides
  3420. the task scheduling,interrupt handlin,and message-passing primitives used to
  3421. support ARexx.
  3422.  
  3423. FUNCTION HOST. A program that manages a public message port for receiving
  3424. function invocation messages. The message port may be the same one used for
  3425. command messages.
  3426.  
  3427. FUNCTION LIBRARY. A collection of functions callable from ARexx and managed as
  3428. an Amiga shared library. Each function library includes an entry point to
  3429. associate a function name with the code to be called.
  3430.  
  3431. HOST ADDRESS. The name of the public message port associated with a host
  3432. application. The host address is used as the unique identifier for the host,and
  3433. should be unique within the system message ports list. Within an ARexx program
  3434. the host address identifies the external host to which commands will be sent.
  3435.  
  3436.                 147
  3437.  
  3438. HOST APPLICATION.  An executable program that program that provides a suitable
  3439. command interface to receive ARexx commands. Most host applications will also
  3440. provide a means to invoke macro programs from within the application.
  3441.  
  3442. INTERRUPT. An event that alters the normal flow of control in a program.
  3443. Interrupts in ARexx refer to events within the program execution and are
  3444. distinct from the hardware-level interrupts managed by the Amiga EXEC system.
  3445.  
  3446. MACRO PROGRAM. A program that implements a complex "macro" operation from a
  3447. series of "micro" commands.
  3448.  
  3449. MESSAGE PACKET. A data structure used to pass information between tasks. A
  3450. message packet is allocated and initialized by one task and then sent to
  3451. another task's message port. After the recipient has processed the message,it
  3452. "replies" the message to the replyport associated with the message.
  3453.  
  3454. MESSAGE PORT. A data structure used as the rendezvous point for message
  3455. passing. A message port provides the anchor for a list of message packets and
  3456. identifies the task to be signalled when a message arrives.
  3457.  
  3458. MULTITASKING. The ability to run more than one program at a time. More
  3459. precisely, multitasking permits the resources of the computer to be shared
  3460. among many tasks without forcing any task to be aware of the others.
  3461.  
  3462. PROCESS. An extension to an EXEC task structure that provides the data fields
  3463. required to use AmigaDOS functions. All ARexx programs run as AmigaDOS
  3464. processes.
  3465.  
  3466. REPLYPORT. A message port designated to receive a returning message packet.
  3467. Each message packet includes a field that specifies its reply port.
  3468.  
  3469. RESIDENT PROCESS. The program responsible for launching ARexx programs and for
  3470. managing various resources used by ARexx. It is structured as a host
  3471. application and opens a public message port named "REXX."
  3472.  
  3473. SHARED LIBRARY. A collection of executable code and data managed as a resource
  3474. by the EXEC operating system. As the name "shared" implies, the code and data
  3475. in a library can be used by more than one task.
  3476.  
  3477. STORAGE ENVIRONMENT.  The collection of data values forming the current state
  3478. of an ARexx program.  Storage environments are strictly nested and only one
  3479. environment is current at any time.
  3480.  
  3481. TASK. An entity consisting of executable code and a data structure managed by
  3482. the EXEC operating system. The task is the smallest program unit that can be
  3483. scheduled and run separately.
  3484.  
  3485.                 148
  3486.  
  3487. TOKEN. The elementary words or atoms of a language. A token can be considered
  3488. as a string of one or more characters forming the smallest unit of the
  3489. language.
  3490.  
  3491. TYPELESS. Data items having no assumed structure or usage. ARexx treats all
  3492. data as typeless character strings and checks for specific characteristics only
  3493. when required by an operation.
  3494.  
  3495.                 149
  3496.  
  3497. AREXX DOCS BROUGHT TO USE BY THE SOUTHERN STAR WILL ASSISTANCE BY RAP.....
  3498.  
  3499. end.